Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Help a Haskell noob

Name: Anonymous 2009-05-07 2:41

I'm running into a funny error, and since you guys hold Haskell second only to Scheme, I though I'd see if you could help me...

I'm trying to get the following code to work:

qLearningUpdate :: ((a,s),n) -> s -> n
qLearningUpdate q s' =
    (fromListBy 0 (maximum.snd.unzip)) (getActions s' q)
    where getActions :: [((a,b),c)]-> b -> [(a,c)]
          getActions s q = (filter ((==s).snd.fst)) q
          fromListBy :: b -> ([a] -> b) -> [a] -> b
          fromListBy d f [] = d
          fromListBy d f xs = f xs


When I just evaluate (fromListBy 0 (maximum.snd.unzip)) (getActions someVariable someAssocList) in ghci , it works fine. When I try to compile the code, I get the following error:

project4.hs:7:0:
    Occurs check: cannot construct the infinite type: n = [((a, s), n)]
    When generalising the type(s) for `qLearningUpdate'

What the hell, man?

Name: Anonymous 2009-05-07 3:21

GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> let getActions s q = (filter ((==s).snd.fst)) q
Prelude> :t getActions
getActions :: (Eq b) => b -> [((a, b), b1)] -> [((a, b), b1)]
Prelude> let fromListBy d f [] = d; fromListBy d f xs = f xs
Prelude> :t fromListBy
fromListBy :: t -> ([t1] -> t) -> [t1] -> t
Prelude> let qLearningUpdate q s' = (fromListBy 0 (maximum.snd.unzip)) (getActions s' q)
Prelude> :t qLearningUpdate
qLearningUpdate :: (Num b, Ord b, Eq b1) =>
                   [((a, b1), b)] -> b1 -> b

look at the types.

Name: Anonymous 2009-05-07 3:44

Thanks. That's embarrassing.

Name: Anonymous 2009-05-07 4:29

GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... Segmentation Fault

Name: Anonymous 2009-05-07 5:44

monad my anus

Name: Anonymous 2009-05-07 8:34

GHCi, version 6.10.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
'-._                  ___.....___
    `.__           ,-'        ,-.`-,
        `''-------'          ( p )  `._
                              `-'      (  Have you read your YAHT today?
                                        \
                              .         \
                               \---..,--'
   ................._           --...--,
                     `-.._         _.-'
                          `'-----''                         Type :ihbt for help.
Prelude>

Name: Anonymous 2009-05-07 14:49

>>6
Prelude> :ihbt

Name: Anonymous 2009-05-07 14:54

>>7
*** Exception: stack pointer monadic overflow

Name: Anonymous 2010-12-27 15:42

Name: Anonymous 2011-01-31 20:31

<-- check em dubz

Name: Anonymous 2011-02-03 8:17

Don't change these.
Name: Email:
Entire Thread Thread List