haskell - Instance errors in Hackage's GenProg example -


so, i'm trying example of genprog working, haskell genetic programming library.

however, i'm getting various instance errors. guess example written in out-dated haskell , has minorly tweaked. code makes sense, don't know enough instances rewrite myself. made few tweaks.

error:

genprogtest.hs:27:10: not deduce (monadrandom-0.1.13:control.monad.random.class.monadrandom (rand stdgen)) arising superclasses of instance declaration context (genexpr e)

that is, first line of instance. (the actual example here: https://hackage.haskell.org/package/genprog-0.1/docs/genprog.html#9 )

{-# language derivedatatypeable, flexibleinstances, flexiblecontexts, multiparamtypeclasses #-} -- put them in 1 line, yo~  import genprog import genprog.genexpr import data.generics import control.monad import control.monad.random  data e = plus e e        | minus e e        | times e e        | div e e        | const int        deriving (typeable,data,eq,show)  eval :: e -> maybe int eval (const c)     = c eval (plus e1 e2)  = liftm2 (+) (eval e1) (eval e2) eval (minus e1 e2) = liftm2 (-) (eval e1) (eval e2) eval (times e1 e2) = liftm2 (*) (eval e1) (eval e2) eval (div e1 e2) | ok        = liftm2 div x1 x2                  | otherwise = nothing   (x1,x2) = (eval e1,eval e2)         ok = x2 /= 0 && liftm2 mod x1 x2 == 0  instance (genexpr e) => genprog (rand stdgen) e   terminal    = const `liftm` getrandomr (1,9)   nonterminal =     r <- getrandomr (0,3)     [liftm2 plus terminal terminal,      liftm2 minus terminal terminal,      liftm2 times terminal terminal,      liftm2 div terminal terminal] !! r      myfitness :: (genprog.genexpr.genexpr e) => int -> e -> double myfitness n e = error + size   error = realtofrac $ maybe maxbound (abs . (n-)) (eval e)         size  = (realtofrac $ nodes e) / 100   


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -