[Haskell-cafe] St. Petersburg Game
Ketil Malde
ketil+haskell at ii.uib.no
Tue Nov 27 08:49:54 EST 2007
manolo at austrohungaro.com writes:
> increment b = b + 1
This is also called 'succ' (for successor).
> main = do let b = 0
> let c = randomRIO (1,2)
> until (c == 1) increment b
> return b
> ERROR "StPetersburg.hs":8 - Type error in application
> *** Expression : until (c == 1) increment b
> *** Term : c == 1
> *** Type : Bool
> *** Does not match : Int -> Bool
Prelude> :t until
until :: (a -> Bool) -> (a -> a) -> a -> a
So until wants a function from a something to a boolean, but you are
giving it (c==1) which is just a boolean.
More generally, I think you should solve this in a more functional
style, perhaps using randomRs to get a list of coin tosses, and take
what you need from that.
-k
--
If I haven't seen further, it is by standing in the footprints of giants
More information about the Haskell-Cafe
mailing list