[Haskell-cafe] Mutually recursive types?

Ron Alford ronwalf at umd.edu
Wed Apr 16 19:22:58 EDT 2008


Here's the setup:
I have a series of problems that use various logical connectives.  The
problem is that they're not all the same.  So instead of creating one
giant datatype (or duplicating much code), I'd like to assemble them
like toy blocks.

I've boiled down an example here:

data LogicalConnective a =
    Not a
    | And [a]
    | Or [a]

data BasicGoal a =
    Atomic String [Term]
    | Empty
    | Logical (LogicalConnective a)
    deriving (Show, Eq)

data PreferenceGoal1 =
    Basic1 PreferenceGoal1
    | Prefer1 PreferenceGoal1

This works OK, but PreferenceGoal1 is a dead end.  I can't combine it
with other connectives.  So I try:

data PreferenceGoal2 a =
    Basic2  (PreferenceGoal2 a)
    | Prefer2 (PreferenceGoal2 a)

And this works fine, but seems impossible to explicitly type (ie,
there is nothing to substitute for 'a' in a type declaration).  Or am
I wrong?

Also, it could be that this is just an ugly way to represent things
(it does require a huge number of constructors).  Any suggestions?

-Ron


More information about the Haskell-Cafe mailing list