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

Jonathan Rioux rioux.jonathan at gmail.com
Thu Dec 6 16:20:57 CET 2012


Indeed. I replied too quickly...


On Thu, Dec 6, 2012 at 10:07 AM, Brent Yorgey <byorgey at seas.upenn.edu>wrote:

> On Thu, Dec 06, 2012 at 09:47:31AM -0500, Jonathan Rioux wrote:
> > 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,
> >
> > From what I've read from this page (
> > http://hackage.haskell.org/trac/haskell-prime/wiki/NoDatatypeContexts ),
> > you simply need to remove « Schedulable a » from 9th line.
> > It would there fore read like so :
> >
> >
> > data Schedulable a => RoundRobin = RoundRobin [a] [a]
>
> I think you meant
>
>   data RoundRobin a = RoundRobin [a] [a]
>
> -Brent
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121206/d6b6506f/attachment.htm>


More information about the Beginners mailing list