Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I do (flip (+).digitToInt) $ '4' 4

Tags:

syntax

haskell

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.

like image 733
NO WAR WITH RUSSIA Avatar asked Oct 19 '10 19:10

NO WAR WITH RUSSIA


People also ask

Can you do a flip turn in butterfly?

In butterfly and breaststroke races, regulations require swimmers to touch the end of the pool with both hands simultaneously before turning back for another length. While they legally can flip turn during butterfly and breaststroke races, it is more common to turn left or right to begin the next lap.


1 Answers

(flip (+).digitToInt) $ '4' 4

is the same as

(flip (+).digitToInt) $ ('4' 4)

Which of course does not work because '4' is not a function.

To get the behavior you want, you can do

(flip (+).digitToInt $ '4') 4

Or just

(flip (+).digitToInt) '4' 4
like image 51
sepp2k Avatar answered Nov 07 '22 14:11

sepp2k