Home > Archive > Functional > April 2007 > Haskell's type system problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Haskell's type system problem
|
|
| Mike Burrell 2007-04-22, 7:03 pm |
| Hi all. I have a data type Foo which looks like:
data Foo a = Foo [[a]]
The problem is that I need Foo to be a Monad, but I need it to
necessarily operate over Enum types, because I use toEnum and enumFrom
in the definition of return.
Attempt #1:
instance (Enum a) => Monad (Foo a) where ....
Obviously this is no good, since "Foo a" is of the wrong kind.
Attempt #2:
data (Enum a) => Foo a = Foo [[a]]
instance Monad Foo where
(Foo xs) >>= f = ....
return x = Foo [[toEnum 0..], [x]]
Unfortunately as soon as I try to use toEnum, I get:
> Foo.hs:11:24:
> Could not deduce (Enum a) from the context (Monad Foo)
> arising from the arithmetic sequence `toEnum 0 .. ' at Foo.hs:11:24-35
> Probable fix: add (Enum a) to the class or instance method `return'
> In the list element: [toEnum 0 .. ]
> In the first argument of `Foo', namely `[[toEnum 0 .. ], [x]]'
> In the definition of `return': return x = Foo [[toEnum 0 .. ], [x]]
I have to admit this error confuses me, as the definition of Foo now
necessitates that it's working over Enum types.
Attempt #3:
data Enum => Monad Foo where....
As attempt #1, a "wrong kind" problem.
Can someone set me on the right track? The error messages seem to
indicate that I should constrain Foo somehow in the instance
declaration, as I've tried to do in attempt #1 and #3, but I can't
think of any way to do this.
Thanks a bunch!
Mike
| |
| Vesa Karvonen 2007-04-22, 7:03 pm |
| Mike Burrell <mburrel@spam.uwo.ca> wrote:
> Hi all. I have a data type Foo which looks like:
> data Foo a = Foo [[a]]
> The problem is that I need Foo to be a Monad, but I need it to
> necessarily operate over Enum types, because I use toEnum and enumFrom
> in the definition of return.
Is this what you want?
data Enum a => Foo a = Foo [[a]]
-Vesa Karvonen
| |
| Mike Burrell 2007-04-22, 7:03 pm |
| On 2007-04-21 15:13:24 -0400, Vesa Karvonen
<vesa.karvonen@cs.helsinki.fi> said:
> Mike Burrell <mburrel@spam.uwo.ca> wrote:
>
>
>
> Is this what you want?
>
> data Enum a => Foo a = Foo [[a]]
Yes, that's exactly what I want! Unfortunately it doesn't work, as
described in my original post.
Thanks,
Mike
| |
| Marcin 'Qrczak' Kowalczyk 2007-04-22, 7:03 pm |
| Dnia 21-04-2007, sob o godzinie 17:59 +0000, Mike Burrell napisa=C5=82(a):
> The problem is that I need Foo to be a Monad, but I need it to=20
> necessarily operate over Enum types, because I use toEnum and enumFrom=20
> in the definition of return.
If constraints on this type are needed, it can't be a monad.
--=20
__("< Marcin Kowalczyk
\__/ qrczak@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
| |
|
|
|
|
|
|
|