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">&lt;<a href=3D"m=
ailto:me at xiao-jia.com" target=3D"_blank">me at xiao-jia.com</a>&gt;</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&#39;m trying to model a round robin scheduler in Haskell.<br>
<br>
&gt; class Schedulable s where<br>
&gt; =A0 isFinal :: s -&gt; Bool<br>
&gt;<br>
&gt; class Scheduler s where<br>
&gt; =A0 add :: (Schedulable a) =3D&gt; a -&gt; s -&gt; s<br>
&gt; =A0 next :: (Schedulable a) =3D&gt; s -&gt; (a, s)<br>
&gt; =A0 empty :: s -&gt; Bool<br>
&gt;<br>
&gt; data Schedulable a =3D&gt; RoundRobin =3D RoundRobin [a] [a]<br>
&gt;<br>
&gt; instance Scheduler RoundRobin where<br>
&gt; =A0 add p (RoundRobin ps qs) =3D RoundRobin (ps ++ [p]) qs<br>
&gt;<br>
&gt; =A0 next (RoundRobin [] =A0 =A0 qs) =3D next (RoundRobin qs [])<br>
&gt; =A0 next (RoundRobin (p:ps) qs) =3D (p, RoundRobin ps (qs ++ [p]))<br>
&gt;<br>
&gt; =A0 empty (RoundRobin [] _) =3D True<br>
&gt; =A0 empty _ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D False<br>
<br>
However, GHC complains that<br>
<br>
&gt; main.hs:9:6:<br>
&gt; =A0 =A0 Illegal datatype context (use -XDatatypeContexts): Schedulable=
 a =3D&gt;<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&#39;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&gt; RoundRobin =3D RoundRobin [a] [a]<br><br></div>Putting =AB Sche=
dulable a) =3D&gt; =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