Last active
July 4, 2018 01:44
-
-
Save mankyKitty/6f1801327f8d89805ffd2f5d21799d2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- Given [a,b] - Gives [a,b,a,b] | |
wutDecoder :: Monad f => Decoder f [Int] | |
wutDecoder = withCursor $ \curs -> do | |
-- Move into the array | |
x <- down curs | |
-- Decode first | |
a <- int pint x | |
-- Step to the right | |
x' <- moveRightN 1 x | |
-- Decode that one | |
b <- int pint x' | |
-- Jump to the left | |
x'' <- moveLeft1 x' | |
-- Decode that one again | |
c <- int pint x'' | |
-- Step back to the right again | |
x''' <- moveRightN 1 x'' | |
-- Decode that one | |
d <- int pint x''' | |
-- Shake it all out | |
pure [a,b,c,d] | |
-- Given [a,b,c] -- Gives [a,c,b,c,a] | |
fooDecoder :: Monad f => Decoder f [Int] | |
fooDecoder = withCursor $ \curs -> do | |
-- Move into array | |
x <- down curs | |
-- Decode '1' | |
a <- int pint x | |
-- Step right twice | |
x' <- moveRightN 2 x | |
-- Decode '3' | |
b <- int pint x' | |
-- Step left once | |
x'' <- moveLeftN 1 x' | |
-- Decode '2' | |
c <- int pint x'' | |
-- Step right once | |
x''' <- moveRightN 1 x'' | |
-- Decode '3' | |
d <- int pint x''' | |
-- Step left twice | |
x'''' <- moveLeftN 2 x''' | |
-- Decode '1' | |
e <- int pint x'''' | |
-- Expecting [1,3,2,3,1] | |
pure [a,b,c,d,e] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment