
Hi, You're pretty close, actually. In general, remember the following: 'type' introduces a type synonym, which means that you're just renaming an existing type, not creating a new one. this means that you don't need constructors. 'data' means that you're defining a new type; in order to do this, you need to specify constructors. for instance:
type Position = Int
here, we've just given Int a new name, Position.
data Bool = True | False
here we've defined a new type (Bool) with two constructors, True and False. or, if the constructors take arguments:
data PairOfInts = PairOfInts Int Int
here, the type is called PairOfInts and the constructor is called PairOfInts; the constructor takes two ints as arguments. HTH, - Hal -- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume On Mon, 3 Nov 2003, Patty Fong wrote:
Hello, I'm fairly new to haskell and functional programming and i'm still trying to get my head around certain concepts.
I'm wondering if anyone can help me convert this abstract syntax into Haskel data and type declarations:
<prolog> ::= (<assertion> ".")*
<assertion> :: = <structure> | <rule>
<rule> ::= <structure> ":-" <structure>("," <structure>)*
<structure> ::= <name> [�(� <term> (�,� <term>)* �)�]
<term> ::= <number> | <variable> | <structure>
<variable> ::= <name>
<name> is simply a String and <number> an Int
This was my attempt feeble attempt but i ran into numerous errors... :
type Prolog = Assertion
data Assertion = Structure | Rule
type Rule = Structure Structure (Structure)
type Structure = Name [ Term (Term)]
data Term = Number | Variable | Structure
type Variable = String
type Name = String
type Number = Int
Any help would be appreciated
TIA
Patrick.
________________________________________________________________________________ Hot chart ringtones and polyphonics. Click here.

At 12:19 03/11/03 +0000, Patty Fong wrote:
<prolog> ::= (<assertion> ".")*
[...]
type Prolog = Assertion
Did you mean this to be a *list* of Assertions? e.g. type Prolog = [Assertion] Otherwise, I think Hal's response covers it. I'd suggest, if only as an exercise, to do the entire definition using 'data' only (no 'type's) ... then figure out if you want to eliminate any of the constructors. #g ------------ Graham Klyne For email: http://www.ninebynine.org/#Contact
participants (3)
-
Graham Klyne
-
Hal Daume III
-
Patty Fong