No subject
Thu Jul 5 12:38:43 CEST 2012
you simply need to remove =AB Schedulable a =BB from 9th line.
It would there fore read like so :
data Schedulable a =3D> RoundRobin =3D RoundRobin [a] [a]
Putting =AB Schedulable a) =3D> =BB in your =AB add =BB and =AB next =BB fu=
nctions should
be sufficient.
Hope this helps,
Jon
On Thu, Dec 6, 2012 at 9:24 AM, Xiao Jia <me at xiao-jia.com> wrote:
> Hi, I'm trying to model a round robin scheduler in Haskell.
>
> > class Schedulable s where
> > isFinal :: s -> Bool
> >
> > class Scheduler s where
> > add :: (Schedulable a) =3D> a -> s -> s
> > next :: (Schedulable a) =3D> s -> (a, s)
> > empty :: s -> Bool
> >
> > data Schedulable a =3D> RoundRobin =3D RoundRobin [a] [a]
> >
> > instance Scheduler RoundRobin where
> > add p (RoundRobin ps qs) =3D RoundRobin (ps ++ [p]) qs
> >
> > next (RoundRobin [] qs) =3D next (RoundRobin qs [])
> > next (RoundRobin (p:ps) qs) =3D (p, RoundRobin ps (qs ++ [p]))
> >
> > empty (RoundRobin [] _) =3D True
> > empty _ =3D False
>
> However, GHC complains that
>
> > main.hs:9:6:
> > Illegal datatype context (use -XDatatypeContexts): Schedulable a =
=3D>
>
> After some searches I realized that datatype contexts are deprecated.
> So how can I model the scheduler without using datatype contexts?
>
> Thanks.
>
> --
> Regards,
> Xiao Jia
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
--f46d04447fb16199e204d030138b
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><div class=3D"gmail_extra">Hello Xiao,<br><br>From what I've read f=
rom this page ( <a href=3D"http://hackage.haskell.org/trac/haskell-prime/wi=
ki/NoDatatypeContexts">http://hackage.haskell.org/trac/haskell-prime/wiki/N=
oDatatypeContexts</a> ), you simply need to remove =AB Schedulable a =BB fr=
om 9th line.<br>
It would there fore read like so :<br><br>data Schedulable a =3D> RoundR=
obin =3D RoundRobin [a] [a]<br><br>Putting =AB Schedulable a) =3D> =BB i=
n your =AB add =BB and =AB next =BB functions should be sufficient.<br><br>=
Hope this helps,<br>
<br>Jon<br><br><div class=3D"gmail_quote">On Thu, Dec 6, 2012 at 9:24 AM, X=
iao Jia <span dir=3D"ltr"><<a href=3D"mailto:me at xiao-jia.com" target=3D"=
_blank">me at xiao-jia.com</a>></span> wrote:<br><blockquote class=3D"gmail=
_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:=
1ex">
Hi, I'm trying to model a round robin scheduler in Haskell.<br>
<br>
> class Schedulable s where<br>
> =A0 isFinal :: s -> Bool<br>
><br>
> class Scheduler s where<br>
> =A0 add :: (Schedulable a) =3D> a -> s -> s<br>
> =A0 next :: (Schedulable a) =3D> s -> (a, s)<br>
> =A0 empty :: s -> Bool<br>
><br>
> data Schedulable a =3D> RoundRobin =3D RoundRobin [a] [a]<br>
><br>
> instance Scheduler RoundRobin where<br>
> =A0 add p (RoundRobin ps qs) =3D RoundRobin (ps ++ [p]) qs<br>
><br>
> =A0 next (RoundRobin [] =A0 =A0 qs) =3D next (RoundRobin qs [])<br>
> =A0 next (RoundRobin (p:ps) qs) =3D (p, RoundRobin ps (qs ++ [p]))<br>
><br>
> =A0 empty (RoundRobin [] _) =3D True<br>
> =A0 empty _ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D False<br>
<br>
However, GHC complains that<br>
<br>
> main.hs:9:6:<br>
> =A0 =A0 Illegal datatype context (use -XDatatypeContexts): Schedulable=
a =3D><br>
<br>
After some searches I realized that datatype contexts are deprecated.<br>
So how can I model the scheduler without using datatype contexts?<br>
<br>
Thanks.<br>
<br>
--<br>
Regards,<br>
Xiao Jia<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href=3D"mailto:Beginners at haskell.org" target=3D"_blank">Beginners at haskel=
l.org</a><br>
<a href=3D"http://www.haskell.org/mailman/listinfo/beginners" target=3D"_bl=
ank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>
--f46d04447fb16199e204d030138b--
More information about the Beginners
mailing list