Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help calling a Haskell function whose arguments involves types which themselves take args

Tags:

haskell

Sorry if the title is ambiguous, essentially I have the following data type declarations:

type Domino = (Integer, Integer)
type Hand = [Domino]
type Board = [Domino]
type DomsPlayer = Hand -> Board -> (Domino, End)
type Score = (Integer, String)

and a function:

playDomsRound :: DomsPlayer -> DomsPlayer -> Int -> (Score, Score)

how do I go about calling the playDomsRound function?


1 Answers

The Cardinal Rule of Typed Application in Haskell is, very simply,

f    :: a  -> b   ===
f (x :: a) :: b

Thus, in your case,

playDomsRound    :: DomsPlayer     -> DomsPlayer     -> Int  -> (Score, Score)   ===
playDomsRound (p :: DomsPlayer)    :: DomsPlayer     -> Int  -> (Score, Score)   ===
playDomsRound (p :: DomsPlayer) (q :: DomsPlayer)    :: Int  -> (Score, Score)   ===
playDomsRound (p :: DomsPlayer) (q :: DomsPlayer) (i :: Int) :: (Score, Score)

and you can write any of the above in your code.

Any expression which has a type, can appear in your code.

Since you've defined

type DomsPlayer = Hand -> Board -> (Domino, End)

the type DomsPlayer is the same as the type Hand -> Board -> (Domino, End). This is what your playDomsRound expects: a function. Not yet applied to any of the arguments that it expects. Just a function.

like image 126
Will Ness Avatar answered Nov 19 '25 15:11

Will Ness



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!