Help ? :)

Hal Daume III hdaume at ISI.EDU
Mon Nov 3 07:29:11 EST 2003


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 =3D Int

here, we've just given Int a new name, Position.

> data Bool =3D True | False

here we've defined a new type (Bool) with two constructors, True and
False.

or, if the constructors take arguments:

> data PairOfInts =3D 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 at isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume

On Mon, 3 Nov 2003, Patty Fong wrote:

>=20
> Hello, I'm fairly new to haskell and functional programming and i'm still
> trying to get my head around certain concepts.
>=20
> I'm wondering if anyone can help me convert this abstract syntax into
> Haskel data and type declarations:
>=20
> <prolog> ::=3D (<assertion> ".")*<?xml:namespace prefix =3D o ns =3D
> "urn:schemas-microsoft-com:office:office" />
>=20
> <assertion> :: =3D <structure> | <rule>
>=20
> <rule> ::=3D <structure> ":-" <structure>("," <structure>)*
>=20
> <structure> ::=3D <name> [=93(=93 <term> (=93,=94 <term>)* =93)=94]
>=20
> <term> ::=3D <number> | <variable> | <structure>
>=20
> <variable> ::=3D <name>
>=20
> =20
>=20
> <name> is simply a String and <number> an Int
>=20
> =20
>=20
> This was my attempt feeble attempt but i ran into numerous errors... :
>=20
> =20
>=20
> type Prolog =3D Assertion
>=20
> data Assertion =3D Structure | Rule
>=20
> type Rule =3D Structure Structure (Structure)
>=20
> type Structure =3D Name [ Term (Term)]
>=20
> data Term =3D Number | Variable | Structure
>=20
> type Variable =3D String
>=20
> type Name =3D String
>=20
> type Number =3D Int
>=20
> =20
>=20
> Any help would be appreciated
>=20
> TIA
>=20
> Patrick.
>=20
>=20
> _________________________________________________________________________=
_______
> Hot chart ringtones and polyphonics. Click here.
>=20



More information about the Haskell-Cafe mailing list