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
(Sorry for the double post, but I think I did something wrong on the first
one...)
--e89a8fb1ebc2f186da04d0302ee6
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
On Thu, Dec 6, 2012 at 9:24 AM, Xiao Jia <span dir=3D"ltr"><<a href=3D"m=
ailto:me at xiao-jia.com" target=3D"_blank">me at xiao-jia.com</a>></span> wro=
te:<br><div class=3D"gmail_quote"><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></blockquote><div>=A0</div>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" target=3D"_blank">http://hackage.haskell.org/trac/ha=
skell-prime/wiki/NoDatatypeContexts</a> ), you simply need to remove =AB Sc=
hedulable a =BB from 9th line.<br>
It would there fore read like so :<div class=3D"im"><br><br>data Schedulabl=
e a =3D> RoundRobin =3D RoundRobin [a] [a]<br><br></div>Putting =AB Sche=
dulable a) =3D> =BB in your =AB add =BB and =AB next =BB functions shoul=
d be sufficient.<br>
<br>Hope this helps,<br>
<br>Jon<br><br>(Sorry for the double post, but I think I did something wron=
g on the first one...)<br></div>
--e89a8fb1ebc2f186da04d0302ee6--
More information about the Beginners
mailing list