[Haskell-beginners] Illegal datatype context when modelling round robin scheduler

Jonathan Rioux rioux.jonathan at gmail.com
Thu Dec 6 15:47:31 CET 2012


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) => a -> s -> s
> >   next :: (Schedulable a) => s -> (a, s)
> >   empty :: s -> Bool
> >
> > data Schedulable a => RoundRobin = RoundRobin [a] [a]
> >
> > instance Scheduler RoundRobin where
> >   add p (RoundRobin ps qs) = RoundRobin (ps ++ [p]) qs
> >
> >   next (RoundRobin []     qs) = next (RoundRobin qs [])
> >   next (RoundRobin (p:ps) qs) = (p, RoundRobin ps (qs ++ [p]))
> >
> >   empty (RoundRobin [] _) = True
> >   empty _                 = False
>
> However, GHC complains that
>
> > main.hs:9:6:
> >     Illegal datatype context (use -XDatatypeContexts): Schedulable a =>
>
> 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
>
>
Hello Xiao,



More information about the Beginners mailing list