Created
October 1, 2019 04:07
Star
You must be signed in to star a gist
Cofree animation
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
module Lib where | |
import Control.Comonad.Cofree | |
import Control.Monad.Reader | |
import Control.Concurrent | |
drawBar :: Float -> IO () | |
drawBar n = putStrLn (replicate (ceiling n) '#') | |
type Animation = Cofree (Reader Float) Float | |
animation :: Cofree (Reader Float) Float | |
animation = unfold go 0 | |
where | |
go :: Float -> (Float, Reader Float Float) | |
go n = ((1 + sin n) * 10, asks (+ n)) | |
loop :: Animation -> IO () | |
loop (a :< next) = do | |
drawBar a | |
threadDelay 10000 | |
loop (runReader next 0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment