> :t (init tail)
: error:
: * Couldn't match expected type `[a]'
: with actual type `[a0] -> [a0]'
: * Probable cause: `tail' is applied to too few arguments
: In the first argument of `init', namely `tail'
: In the expression: (init tail)
> :t (init . tail)
: (init . tail) :: [a] -> [a]
> :t init $ tail
: error:
* Couldn't match expected type `[a]'
with actual type `[a0] -> [a0]'
* Probable cause: `tail' is applied to too few arguments
In the second argument of `($)', namely `tail'
In the expression: init $ tail
> chopEnds = init $ tail
> chopEnds [1,2,3]
error: ...
* Variable not in scope: chopEnds1 :: [Integer] -> t
...
but then
Not sure what I'm missing here. It doesn't make sense to me that the last expression works, but no version of a closure
chopEnds = init $ tail
does.
On Mon, Jan 25, 2021 at 7:58 PM Kim-Ee Yeoh <
ky3@atamo.com> wrote:
init $ tail [1,2,3]
= init (tail ([1,2,3])) -- a la Lisp
Now, functional programming is awesomest at abstractions. What if we could abstract out "init (tail"?
Then we could write
chopEnds = init (tail
But that looks weird. It's only got the left half of a parens pair!
Does that explain why you should not expect the same result?
A separate question is why the compiler even type-checks "init $ tail" in the first place. What do you think is going on there?
--
-- Kim-Ee
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________