I'm just wondering how $
works: I was expecting
> (flip (+).digitToInt) $ '4' 4
<interactive>:1:24:
Couldn't match expected type `t -> Char'
against inferred type `Char'
In the second argument of `($)', namely '4' 4
In the expression: (flip (+) . digitToInt) $ '4' 4
In the definition of `it': it = (flip (+) . digitToInt) $ '4' 4
to apply (flip (+).digitToInt)
to 4 4
, however it didn't work. How come? I've found this works
> (flip (+).digitToInt) '4' 4
8
it :: Int
And, I see the type of:
> :t (flip (+).digitToInt)
(flip (+).digitToInt) :: Char -> Int -> Int
But, I don't understand why I can't call apply (flip (+).digitToInt)
explicitly
This confusion comes from the basic observation that
digitToInt $ '5'
and
digitToInt '5'
are permitted with the same effect - except that the top has slightly more line noise.