Given the above functions, I'm confused why let x = sumOfSquares . returnGreatest2 returnsbut sumOfSquares $ returnGreatest2 3 5 7 does the right thing. Since the type coming out of returnGreatest2 is the same as the type sumOfSquares expects, I would think I'd be able to compose them.
Having fun working through a Haskell tutorial... One problem posed is as you see in the subject line... this is one I'd really like to figure out, but I'm at a loss... I've used any like so:
I'm having some trouble with performing simple addition, subtraction -- any kind of algebra really with Haskells newtype.
An exercise in Haskell from First Principles says to implement filter using foldr and this is what I came up with but it feels and looks clunky. Is there a more natural way to implement it with a foldr?
So I was asked whether these 3 type expressions where equivalent in Haskell:if I take away the parenthesis I'm left with this
I came across the paper "https://www.cs.ox.ac.uk/jeremy.gibbons/publications/iterator.pdf" which has code examples in quite an abstract pseudo haskell syntax.
In "A Gentle Introduction to Haskell" we have such declaration of Tree's type:Let's to make some values of this type:
When I call safeHead with the argument (4:5:3::) the pattern only evaluates the argument to see if either it is empty or if it has a head. So despite the nonsensical bit ":" it should not throw an error since this part is not even evaluated.
(Note: I'm phrasing the question using Haskell terminology; answers are welcome to use the same terminology and/or the mathematical language of category theory, including proper mathematical definitions and axioms where I speak of functor and monad laws.)
So I have to define a safe version of the head function that would not throw an error when  is passed as the argument. Here it is: