class instance with nested types
Matthias Höchsmann
mhoechsm@techfak.uni-bielefeld.de
Fri, 27 Oct 2000 12:16:19 +0200
This is a multi-part message in MIME format.
--Boundary_(ID_5jIOsd3oqicabXDXApeVOg)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT
Hello,
I have the following problem:
basic datatypes
> type Sequence a = [a]
> data Tree a = N a (Forest a) deriving (Ord,Eq,Show)
> type Forest a = Sequence (Tree a)
i want to construct a class Xy
> class Xy s a where
> test :: s a -> a
and make an instance for list of characters
> instance Xy [] Char where
> test [a] = a
this works, and an instance for a forest and tried something like this
> instance ([] Tree) Char where
> test x@(N a xs):txs = a
I get illegal type errors. Is it possible to use nested types in a class ?
Hope you can help me
Matthias
--Boundary_(ID_5jIOsd3oqicabXDXApeVOg)
Content-type: text/html; charset=iso-8859-1
Content-transfer-encoding: 7BIT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hello,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I have the following problem:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>basic datatypes</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>> type Sequence a = [a]</FONT></DIV>
<DIV><FONT face=Arial size=2>> data Tree a = N a (Forest a) deriving
(Ord,Eq,Show)</FONT></DIV>
<DIV><FONT face=Arial size=2>> type Forest a = Sequence (Tree a)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>i want to construct a class Xy</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>> class Xy s a where</FONT></DIV>
<DIV><FONT face=Arial size=2>> test :: s a
-> a</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>and make an instance for list of
characters</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>> instance Xy [] Char where</FONT></DIV>
<DIV><FONT face=Arial size=2>> test [a] =
a</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>this works, and an instance for a forest and tried
something like this</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>> instance </FONT> <FONT face=Arial
size=2>([] Tree) Char where</FONT></DIV>
<DIV><FONT face=Arial size=2>> test x@(N a xs):txs = a</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I get illegal type errors. Is it possible
to use nested types in a class ?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Hope you can help me </FONT></DIV>
<DIV><FONT face=Arial size=2>Matthias</FONT></DIV>
<DIV> </DIV></BODY></HTML>
--Boundary_(ID_5jIOsd3oqicabXDXApeVOg)--