Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicit type signatures for polymorphic types

Tags:

haskell

I'm reviewing Haskell: The Craft of Functional Programming, however the type signatures on page 356 have thrown me for a loop.

Here is a simple one:

succeed :: b -> Parse a b
succeed val inp = [( val, inp )]

How can that be b -> Parse a b, if

succeed Int -> Int
succeed a = a

and,

succeed Int -> Int -> Int
succeed a b = a + b

The amount of arguments your taking has to be in the type declaration right? How can you take val, and imp, if your type declaration only has one type variable: succeed :: b -> Parse a b is supposed to read, take one variable of type a and return a type of Parse a b, not take two variables... where is inp permitted?

like image 583
NO WAR WITH RUSSIA Avatar asked Jul 16 '26 09:07

NO WAR WITH RUSSIA


1 Answers

Because Parse is a type synonym with -> in its expansion. Example:

type Foo = Int -> Int

succeed :: Int -> Foo
succeed a b = a + b
like image 195
keegan Avatar answered Jul 18 '26 12:07

keegan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!