Haskell: Multiple declaration of datatype -
this question has answer here:
i have little problem while creating data types.
i have 2 data types, football , tennis
data football = football { players :: players , stadium :: stadium } data tennis = tennis { players1 :: players , stadium1 :: stadium } and want create other datatype sport using constructor datatype football , tennis data sport = football | tennis a , following error, multiple declarations of football don't understand doing wrong.
best regards
your idea correct in spirit haskell uses tagged unions (also called "discriminated unions", "disjoint unions", "variants", , "sum types"). means need additional tag determine if sport constructed football or if constructed tennis.
data sport = sportfootball football | sporttennis tennis these tags known in haskell data constructors. is, defines constructor sportfootball :: football -> sport , constructor sporttennis :: tennis -> sport.
suppose haskell did not require tag, type?
data untaggedint = int | int an untagged union should have property (x | x) = x , must equivalent to:
data untaggedint = int whereas tagged unions can define:
data taggedint = int | int that is, tagged unions not idempotent.
also consider else happens without constructors. suppose have definition such as:
data untaggedlists = string | [string] and tasked finding type of expression "hello world". should type string or untaggedlists? suppose have similar definition:
data anotheruntaggedlists = string | [string] is true untaggedlists , anotheruntaggedlists equal types?
these not unanswerable questions, demonstrate profound systematic difference between having tags , not.
Comments
Post a Comment