Reputation: 60912
Scott has a nice talk about domain modeling in F#, and presents the following slide:
Is the Deal
type a record or union type?
My question is regarding this line:
type Deal = Deck -> (Deck*Card)
I'm not sure I understand this. How can we simply create a function and shove it into a type? I thought that the data and functionality are supposed to be separate?
Upvotes: 1
Views: 69
Reputation: 6629
Neither. It's a function type, more precisely it's an alias for the function type described by the signature Deck -> (Deck * Card)
. The way aliases work is that you can use them to make things clearer wherever you state a type yourself, but if the compiler infers the type, that will always be the original unaliased type.
So in this case, wherever the type Deal
is given, any function that takes a Deck
and returns a tuple of Deck
and Card
will be accepted.
Upvotes: 3