haskell - UndecidableInstances and newtypes -


i have undecidableinstances problem haven't been able figure out how avoid using newtype. here's had originally:

{-# language typefamilies, flexiblecontexts #-}  class record r   key :: r -> string  class (record r) => sizedrecord r   size :: r -> int  class database d   type dbrecord d  class (record a) => agent   agentid :: -> string   agentid = key  class (database (uagentdb u), agent (uagent u), record (uagent u))       => universe u   type uagent u   type uagentdb u   -- plus other stuff  data simpleuniverse d = simpleuniverse   {     sudb :: d     -- plus other stuff   } deriving (show, eq)  instance (record (dbrecord d)) => universe (simpleuniverse d) -- line 28   type uagent (simpleuniverse d) = dbrecord d   type uagentdb (simpleuniverse d) = d   -- plus other stuff 

the message is

amy9.hs:28:10:     constraint no smaller instance head       in constraint: record (dbrecord d)     (use -xundecidableinstances permit this)     in instance declaration `universe (simpleuniverse d)' 

i want avoid undecidableinstances because code going in reusable library, try declaring newtype:

newtype simpleuniverse2 u = simpleuniverse2 { fromadditivegroup :: u }  instance (record (dbrecord u)) => universe (simpleuniverse2 u)   type uagent (simpleuniverse2 u) = dbrecord u   type uagentdb (simpleuniverse2 u) = u   -- plus other stuff 

but same error. i've read answers other questions on undecidableinstances, haven't been able solve this.

as horrible kludge, double-wrapping , using flexibleinstances seem trick:

import control.monad.identity      instance (database u, agent (dbrecord u), record (dbrecord u)) =>          universe (identity (identity u))   type uagent (identity (identity u)) = dbrecord u   type uagentdb (identity (identity u)) = u 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -