Skip to content

Instantly share code, notes, and snippets.

# qbhertDomain1 8
[ [1]
, [1,2]
, [3,1,2]
, [3,1,2,4]
, [5,3,1,2,4]
, [5,3,1,2,4,6]
, [7,5,3,1,2,4,6]
, [8,7,6,5,4,3,2,1]
@ClathomasPrime
ClathomasPrime / performIfSuccedes.hs
Created April 16, 2019 22:21
MonadState code which only "actually" alters state if some subcomputation succedes
performIfSuccedes :: MonadState s m => m (Maybe a) -> m (Maybe a)
performIfSuccedes m = do
s <- get
res <- m
case res of
Nothing -> put s >> return Nothing
Just a -> return (Just a)
module Q6 where
import Control.Monad
import Control.Monad.Random
import Data.Numbers.Primes
import Data.List
import Data.Function
thing :: MonadRandom m => Int -> m [Int]
thing n = thing' n