Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Last active September 21, 2017 22:14
Show Gist options
  • Save tonymorris/61ff53983694b32c0a76 to your computer and use it in GitHub Desktop.
Save tonymorris/61ff53983694b32c0a76 to your computer and use it in GitHub Desktop.
This is how we add 10 to every element in a list
import Control.Applicative
import Control.Monad.ST
import Control.Monad
import Data.STRef
while ::
Monad f =>
f Bool
-> f a
-> f ()
while p a =
p >>= (`when` (a >> while p a))
map' ::
(a -> b)
-> [a]
-> [b]
map' f list =
runST $ do
l <- var id
c <- var list
while
(notEmpty <$> at c)
(do m <- at l
d <- at c
l .= (m . (f (head d):))
c .= tail d)
($[]) <$> at l
add10 ::
[Int]
-> [Int]
add10 =
map' (+10)
-- support
notEmpty = not . null
at = readSTRef
var = newSTRef
(.=) = writeSTRef
infixr 4 .=
@FranklinChen
Copy link

Wicked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment