Problem with using Rand in a let

Why does

let mbMove = case playerType of
        Person _ -> do
            Nothing

        Computer strategy -> do
            case strategy of    
                RandomPick -> do 
                    let moves = ...
                    randN <- H.liftEff $ randomInt 0 $ length moves - 1 
                    index moves randN 
                    ...

give compiler error on liftEff:

No type class instance was found for

Control.Monad.Eff.Class.MonadEff ( random :: RANDOM
                                 | t2
                                 )
                                 Maybe

but yet, this makes it happy:

RandomPick -> do 
    let moves = ...
    head moves

???

Cross-posted on Slack, where problem was solved by MonoidMusician (https://functionalprogramming.slack.com/archives/C717K38CE/p1532019853000258?thread_ts=1532001667.000072&cid=C717K38CE):

You need access to Effect to get the random int, but in a let binding you can only do pure computations (essentially)

mbMove <- case playerType of
    Person _ -> do
        pure Nothing

    Computer strategy -> do
        case strategy of    
            RandomPick -> do
                let moves = ...
                randN <- H.liftEff $ randomInt 0 $ length moves - 1
                pure $ index moves randN
1 Like