I'm writing some data types in Haskell to represent formal English grammar.
data S = NP VP
So far so good, a sentence is just a noun phrase and a verb phrase. Marvel at the elegant beauty of algebraic data types!
I'll also define a determiner and adjective as:
data D = A | An | The
type Adj = String -- Too many adjectives for me to list, so I make it a type
-- synonym for String.
Now, I'm having issues defining NP, which is a noun with an optional determiner and adjective. My first natural instinct is to use Maybe:
data NP = Maybe D Maybe Adj N
which gives me the error:
Expecting one more argument to `Maybe' In the type `Maybe' In the definition of data
constructor `Maybe' In the data type declaration for `NP'
(Note that the error doesn't change based on whether or not I have imported Data.Maybe)
The only way I ever got this to work was by using record syntax:
data NP' = NP' {determiner :: Maybe D, adjective :: Maybe Adj, noun :: N}
Why does this only work when I use record syntax?
Try
data NP = NP (Maybe D) (Maybe Adj) N
You need to
NP
Maybe
which I've done by disambiguating it with parentheses