Created
August 9, 2024 10:33
-
-
Save zouppen/9e13620bbbfb277f84046f9da6ec6670 to your computer and use it in GitHub Desktop.
Small example about decoding values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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