Re: Implementing Johnson algorithm
  Home FAQ Contact Sign in
comp.lang.haskell only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Implementing Johnson algorithm         

Group: comp.lang.haskell · Group Profile
Author: Dan Doel
Date: Sep 19, 2007 13:10

andrea wrote:
> Why
> data Versus = Versus 0 | Versus 1 or
> data Versus = 0 | 1
>
> are wrong?

The format for a data declaration is:

data TypeName = Contstuctor1 Type11 Type12 ...
| Constructor2 Type21 Type22 ...
| ...

So 'data Versus = Versus 0 | Versus 1' is wrong for a couple reasons:

1) Both constructors are named the same thing, so there'd be no way to tell
which one you want on use.

2) 0 and 1 aren't the names of types, they're the names of numeric values.

In 'data Versus = 0 | 1', the error is that 0 and 1 are not available for
constructor names, already being numeric values.

What you want is something like:

data Versus = Up | Down

Although those might not be good names, I don't know (Left and Right are
taken by predefined types already). Of course, if all you have are two
options, there's already a type like that defined:

data Bool = False | True

Of course, if you can give relevant names to your alternate type, that's a
fine idea, as it can make the algorithm clearer than just using Bool.

Hope that helps.

-- Dan
no comments
diggit! del.icio.us! reddit!