Skip to content

Instantly share code, notes, and snippets.

@zouppen
Created August 9, 2024 10:33
Show Gist options
  • Save zouppen/9e13620bbbfb277f84046f9da6ec6670 to your computer and use it in GitHub Desktop.
Save zouppen/9e13620bbbfb277f84046f9da6ec6670 to your computer and use it in GitHub Desktop.
Small example about decoding values
{-# LANGUAGE RecordWildCards #-}
module Korttipeli where
import Control.Monad.State
decodeValue :: Integer -> State Integer Integer
decodeValue n = state $ \s -> let (s', ord) = divMod s n
in (ord, s')
decodeValues :: Traversable t => t Integer -> Integer -> Maybe (t Integer)
decodeValues xs a = case runState (mapM decodeValue xs) a of
(out, 0) -> Just out
_ -> Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment