haskell - Parse error on a data type I defined -



haskell - Parse error on a data type I defined -

i'm trying create card game in haskell

i defined next info types

data rank = r2 | r3 | r4 | r5 | r6 | r7 | r8 | r9 | r10 | j | q | k | deriving (bounded, enum, eq, ord) info suit = s | h | d | c deriving (bounded, enum, eq, ord, show) info card = card { rank :: rank, suit :: suit } deriving (eq, ord) type deck = [card]

i trying define constant total deck of cards such:

fulldeck :: deck fulldeck = [ card{r2,s}..........

with plenty more cards behind every card in deck when seek compile error "parse error on input r2" defined r2 part of rank info type, , unsure why not correctly working

you mixing positional , field notation. either use:

card r2 s

or

card{rank=r2, suit=s}

the expression:

card{r2,s}

is not valid.

there namedfieldpuns extension allow write similar wrote. in particular allows things like:

acard = card{rank,suit} rank = r2 suit = s

instead of:

acard = card{rank=rank, suit=suit} rank = r2 suit = s

however, in case must utilize name of fields, compiler able infer fields want fill.

the extension allows avoid repetition in patterns too:

f (card{rank, suit}) = ...

instead of:

f (card{rank=rank, suit=suit}) = ...

which syntax must utilize without extension enabled.

haskell types

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -