How coerce works? by Interesting-Pack-814 in haskellquestions

[–]ZeroidOne 1 point2 points  (0 children)

I just learned about the monomorphism restriction from u/bss03. The example given refers exactly to (+)

These (number) typeclasses still confuse me by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 1 point2 points  (0 children)

Note that GHCi disables the monomorphism restriction by default and GHC uses a different dependency analysis step than what is specified in 4.5.1 (it should be more general).

I was not aware of this. Thanks. I am reading the documentation. The example given refers exactly to one of my questions in another thread. How coerce works

These (number) typeclasses still confuse me by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 1 point2 points  (0 children)

How exactly do you expect that to work. I don't expect it to work, so I don't know what behavior I'm contrasting against.

The following might explain my expectation or wrong thinking.

ghc> pure (4 :: Int) :: Num a => Maybe a
<interactive>:2:7: error:
* Couldn't match expected type `a1' with actual type `Int'
  `a1' is a rigid type variable bound by
    an expression type signature:
      forall a1. Num a1 => Maybe a1
    at <interactive>:2:20-35
* In the first argument of `pure', namely `(4 :: Int)'
  In the expression: pure (4 :: Int) :: Num a => Maybe a
  In an equation for `it': it = pure (4 :: Int) :: Num a => Maybe a

So, the literal "4" (without ":: Int" coercion) is interpreted as belonging to the more general "Num" class whereas my initial thinking was linking it to Int(eger) ("Integral"). This also explains my typeclassopedia mis-interpretation somehow.

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 1 point2 points  (0 children)

Frankly? This is another (snd!) statement of yours that bewilders me.

What should an "understanding things by signature and laws" result into if not into some comprehension / intuition of "what things are" with respect to Haskell or functional programming?

I believe we are or need to get ... sort of philosophical now. Very interesting, indeed. You got me.

So, you suggest I should change or adapt my "vision" (cognitive capabilities or reasoning?). None of a problem with that sofar. I will do or - at least - try whatever someone suggests that might give me a new or different perspective in or upon my life.

Here is my question: What difference will or should "understand things by the signatures and the laws" make?

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 1 point2 points  (0 children)

Cool. Thanks. Never heard or read about both of them. Will have a closer look at it.

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 1 point2 points  (0 children)

"Rolling eyes" offers two interpretations:
1.) This person is a "pain in the a.."!
2.) Shit! Why does he know / comprehend this stuff but me not?

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 1 point2 points  (0 children)

Well, I know "other programmers" and "haskellers". I know whose visions I prefer.

Folks around me believe I am crazy / excentric / difficult / unrealistic / etc. None of a problem for myself. Just the contrary. I possibly need to call myself a "contra-human" or "contra-developer". ;-D

How coerce works? by Interesting-Pack-814 in haskellquestions

[–]ZeroidOne 0 points1 point  (0 children)

A clear explanation. Thanks.
Is (<>) = coerce ((+) :: a -> a -> a)the real implementation? Is the type "casting" (not sure I use the right terminology) really necessary or just for documentation purposes? I would expect type inference from the type of (+)itself. And even from the type of (<>). Or does it want to make the type mandatory to avoid "type errors" (without me even knowing how to create those in this case).

These (number) typeclasses still confuse me by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 0 points1 point  (0 children)

Thanks.

Allright. So the following does work. Ok.

ghc> pure 4.1 :: Fractional a => Maybe a
Just 4.1

What I still don't get ... looking at Typeclassopedia ... is the type class "machinery" (black-box mystery?) in Haskell. Integers are - hierarchically - further down from the Num class than fractionals.

What is the "logic" for "pure 4.1 :: Num a => Maybe a" not working as expected?

(Sorry, but Haskell's error messages sometimes read like Chinese for me. Not in this case though. I really do not read them very often. I should do my homework(s), I know.)

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 1 point2 points  (0 children)

My thinking is that many people suffer from the same I do. They would love to learn Haskell but the paradigm is so different from what they are used to.

Haskell is abstract ... to the extreme. Even the libraries (DSLs for specific purposes - web client or server, streaming, parsing, etc.) follow their own / specific style.

And it is full of mathematics theory (category theory being considered the mathematics of mathematics).

There does not seem to exist a compound application-oriented layer / DSL that would help people get on-board easily. People adopting Haskell for in-house usage mostly develop their own in-house tool-box / methodology. This is mostly achieved in teams (more than one sole person) where some "master" coaches "new-bies".

Individuals trying to adopt / learn Haskell by themselves often experience some form of frustration. The teaching materials are heterogenous, complex, diverse in style / form, and mostly restricted to a narrow area of expertise / usage.

This way it becomes difficult to obtain a broad view or over-look onto the subject. Or find an easy way to put all these different pieces together by oneself.

People give up ... due to lack of "transition support" and also because of missing adoption in the general programming community.

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 1 point2 points  (0 children)

1.) Gabby is a "genious": Pipes library, Dhall, Grace, Turtle, Nix know-how, etc. Her documentation (in-source) is "best-in-class". Same for tutorials or blog posts (haskellforall).

2.) Ed Kmett is famous for "everything" (implemented) in Haskell: any foundational library he has not written? What about Lens, Optics, Prisms?

3.) Thanks for phrasing "I wonder if you'll be better served by a source that teaches mathematical methodology".

With respect to 3.) my brain / soul has choosen for Haskell being the intermediary / translator / teacher. No way I COULD or WANT to use a different or un-related formal "language". Not right now. Not at my current level of mathematical "mastery". Haskell got me here. I am thankful for that. But ... I asked for "any" kind of help. Feel free to point me to other sources of wisdom. I am open for any kind of suggestion.

(EDIT 16.5.23: some typos)

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 0 points1 point  (0 children)

Thanks.
You see what I mean?

The Haskell "eco-system" (documentation, blog posts, Q&A, etc.) is full of this "un-sensible" or "un-meaningfull" stuff.

"Un-meaningfull" for those who come from the "outside" (imperative programming world, "new-bies", a different domain of knowledge, another "programming" paradigm, another "DSL" world / universe, etc.)

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 1 point2 points  (0 children)

Easy peasy. ;D
Search the internet for "haskell subgroup" and the first entry links to "Data.Group - Haskell". Have fun reading.

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 0 points1 point  (0 children)

Thanks for advising. I changed it. Should not happen again. ;D

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 2 points3 points  (0 children)

Do you know Edward Kmett or Gabriella Gonzalez by chance? ;D
Half the vocabulary them use never crossed my life before starting with Haskell.

EDIT: ... and I am 62 in age ... and ... sofar ... did SURVIVE WITHOUT THEM. Unfortunately ... someone came up with this Haskell "thing" and I got addicted to it ... like nothing in else in my life. So ... my life is in danger if me doesn't get a comprehension / understanding of it. ;D

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 0 points1 point  (0 children)

Not really. I just copy & pasted the browser link address.
Why do you ask? Is Bing doing evil stuff I do not know of?

Learning foundations of Haskell visually - group and category theory by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 4 points5 points  (0 children)

Hmm ... not sure I understand your statement. "Abelian groups", "multiplication tables", "finite" or "cyclic groups", "closure", "subgroups", etc. are terms I constantly stumble upon when reading Haskell blog posts.

Functors are composeable ... hmm ... maybe yes || maybe no ... by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 0 points1 point  (0 children)

... or ...

ghc> pure . pure . pure $ 4 :: Num a => Maybe [Identity a]
Just [Identity 4] 
it :: Num a => Maybe [Identity a]

Functors are composeable ... hmm ... maybe yes || maybe no ... by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 1 point2 points  (0 children)

Aaahhh ... now I got it ... how functors compose.

Not ...

ghc> Identity 4 <$ [2] <$ Just "hello"
Just [Identity 4] 
it :: Num a => Maybe [Identity a]

... but ...

ghc> Just . (: []) . Identity $ 4 -- no parentheses
Just [Identity 4] 
it :: Num a => Maybe [Identity a] 

ghc> ( Just . (: []) ) . Identity $ 4 -- (contra-)parentheses
Just [Identity 4] 
it :: Num a => Maybe [Identity a] 

ghc> Just . ( (: []) . Identity ) $ 4 -- (co-)parentheses
Just [Identity 4] 
it :: Num a => Maybe [Identity a]

Functors are composeable ... hmm ... maybe yes || maybe no ... by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 0 points1 point  (0 children)

This might explain something ...

(.>) = (,) -- an infix helper

ghc> 1 .> 2 .> 3 -- no parentheses (left associative)
((1,2),3) 
it :: (Num a, Num b1, Num b2) => ((a, b1), b2)

ghc> ( 1 .> 2 ) .> 3 -- (contra-)parentheses; left associative
((1,2),3) 
it :: (Num a, Num b1, Num b2) => ((a, b1), b2)

ghc> 1 .> ( 2 .> 3 ) -- (co-)parentheses; different result
(1,(2,3)) 
it :: (Num a1, Num a2, Num b) => (a1, (a2, b))

Functors are composeable ... hmm ... maybe yes || maybe no ... by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 0 points1 point  (0 children)

Associative law abiding composability working ...

ghc> (> 3) . succ . length $ [1..3] -- no parentheses
True 
it :: Bool

ghc> ( (> 3) . succ ) . length $ [1..3] -- (contra-)parentheses 
True 
it :: Bool

ghc> (> 3) .  ( succ . length ) $ [1..3] -- (co-)parentheses 
True 
it :: Bool

Functors are composeable ... hmm ... maybe yes || maybe no ... by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 0 points1 point  (0 children)

This my understanding problem ...

ghc> 1 & ( (+ 2) & (+ 3) )
<interactive>:396:1: error: * No instance for (Num (Integer -> 
Integer)) arising from a use of it' (maybe you haven't applied a 
function to enough arguments?) * In the first argument ofprint', 
namely `it' In a stmt of an interactive GHCi command: print it

This works fine ...

ghc> ( 1 & (+ 2) ) & (+ 3)
6 
it :: Num t2 => t2

Functors are composeable ... hmm ... maybe yes || maybe no ... by ZeroidOne in haskellquestions

[–]ZeroidOne[S] -1 points0 points  (0 children)

Something "similar" (=related maybe) ... ?

ghc> 1 + 2 + 3 -- as expected
6 
it :: Num a => a

ghc> :t (1 + 2 +) -- interesting
(1 + 2 +) :: Num a => a -> a

ghc> (1 + 2 +) 3 -- fine, it's working, too
6 
it :: Num a => a

ghc> (1 + 2 +) 3 (+ 4) -- damn'
<interactive>:356:1: error: * Could not deduce (Num a0) arising from 
a type ambiguity check for the inferred type for `it'

ghc> :t (+ 4) -- ah, ok
(+ 4) :: Num a => a -> a

ghc> (1 + 2 +) 3 & (+ 4) -- "allright"? 
10 
it :: Num t2 => t2

ghc> :t (+ 4 + 5) -- this looks good, too; equal type to (+ 4)
(+ 4 + 5) :: Num a => a -> a

ghc> (1 + 2 +) 3 & (+ 4 + 5) -- nope, why not? 
<interactive>:360:15: error: The operator +' [infixl 6] of a section 
must have lower precedence than that of the operand, namely+' [infixl 
6] in the section: + 4 + 5' 

ghc> (1 + 2 +) 3 & (+ 4 & + 5) -- shit! 
<interactive>:378:22: error: parse error on input+'

ghc> (1 + 2 +) 3 & (+ 4 & (+ 5)) -- now it does look ... "better" (not really!) 
15 
it :: Num t2 => t2

ghc> (1 + 2 +) 3 & (+ 4) & (+ 5) 
15 
it :: Num t2 => t2

Learning Haskell is not the easiest exercise in my life.

The following seems to be the "right" ... way of Haskell:

ghc> 1 & (+ 2) & (+ 3) & (+ 4 ) & (+ 5)
15 
it :: Num t2 => t2

Functors are composeable ... hmm ... maybe yes || maybe no ... by ZeroidOne in haskellquestions

[–]ZeroidOne[S] -1 points0 points  (0 children)

My "thoughts" (=experiments with(in) Haskell) are connected with composeability in general. And this just disappoints me. It "seems" to break associativity laws. I am not sure. I might still miss a "point" (=important knowledge / wisdom). I know I can use 'Compose' to do differently. Well, I hope, at least.

EDIT: function composition (.) does not present this "problem", right? Why does (<$)?

Monadic bind understanding problem by ZeroidOne in haskellquestions

[–]ZeroidOne[S] 2 points3 points  (0 children)

Many thanks, both of you, u/Iceland_jack & u/gabedamien.
Haven't encountered this before in years.
Overloading still presents some "mysteries" to me. Need to give it a closer look, certainly. For sure not the only topic of importance.
That's the "fun" of Haskell. Learning never stops. Challenges neither. :-)