I'm something of a Haskell beginner. I'd like to know why the following isn't working:
import System.Random
simulator :: (RandomGen g) => g -> Double -> (Bool, g)
simulator gen p = (x <= p, gen2)
where (x, gen2) = random gen :: (Double, g)
The error I get is:
• Couldn't match type ‘g’ with ‘g1’
‘g’ is a rigid type variable bound by
the type signature for:
simulator :: forall g. RandomGen g => g -> Double -> (Bool, g)
at simulate.hs:10:1-54
‘g1’ is a rigid type variable bound by
an expression type signature:
forall g1. (Double, g1)
at simulate.hs:12:37-47
Expected type: (Double, g1)
Actual type: (Double, g)
• In the expression: random gen :: (Double, g)
In a pattern binding: (x, gen2) = random gen :: (Double, g)
In an equation for ‘simulator’:
simulator gen p
= (x <= p, gen2)
where
(x, gen2) = random gen :: (Double, g)
• Relevant bindings include
gen :: g (bound at simulate.hs:11:11)
simulator :: g -> Double -> (Bool, g) (bound at simulate.hs:11:1)
where (x, gen2) = random gen :: (Double, g)
It seems Haskell is unable to match the separate instances of the type variable g
. Any clues?