Skip to content

Instantly share code, notes, and snippets.

View fumieval's full-sized avatar
🐦
Birb

Fumiaki Kinoshita fumieval

🐦
Birb
View GitHub Profile
@fumieval
fumieval / progLA.hs
Last active August 29, 2015 14:05 — forked from myuon/progLA.hs
{-# LANGUAGE GADTs, FlexibleContexts, TemplateHaskell #-}
import Control.Monad.State
import qualified Data.IntMap as M
import Control.Lens
data Field = Field String (M.IntMap Chara) deriving (Show)
data Chara = Chara String deriving (Show)
updateField f (Field s m) = Field (f s) m
updateChara f (Chara s) = Chara (f s)
{-# LANGUAGE Rank2Types #-}
import Control.Comonad
data Saucer e a = Saucer a (forall x. e x -> (x, Saucer e a))
instance Functor (Saucer e) where
fmap f (Saucer a h) = Saucer (f a) (fmap (fmap f) . h)
instance Comonad (Saucer e) where
extract (Saucer a h) = a
{-# LANGUAGE ViewPatterns #-}
module Source where
import Control.Applicative
import Control.Comonad
import qualified Data.Sequence as Seq
import Control.Monad.Identity
type Time = Double
data Source f a = Source !a (Time -> f (Source f a))
-- https://github.com/ekmett/free/tree/35467bea6916a2efdd7182d071751af685344b1a
import Control.Monad.Identity
import qualified Control.Monad.Trans.Iter as I
import qualified Control.Monad.Trans.Iter.Reflection as R
import Control.Monad.State
import Data.IORef
destruct :: I.IterT IO a -> IO a
destruct m = do
export PS1="$PS1\nβ˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…β˜†β˜…"
@fumieval
fumieval / sprite.hs
Created February 22, 2014 06:16
Lens-based sprite
{-# LANGUAGE MultiWayIf, ExistentialQuantification, OverloadedStrings #-}
import FreeGame
import qualified Data.IntMap as IM
import Control.Lens
import Control.Monad.State
import Control.Applicative
import Control.Monad
import Control.Monad.Identity
import qualified Data.Traversable as T
{-# LANGUAGE GADTs, FlexibleInstances, FlexibleContexts, Rank2Types #-}
import Prelude hiding (getChar, putChar)
import Control.Monad.Operational.Mini
import qualified System.IO as IO
class Monad m => MonadCharIO m where
getChar :: m Char
putChar :: Char -> m ()
@fumieval
fumieval / cooperational.hs
Created June 9, 2013 02:37
Cooperationalγ‚³γƒ’γƒŠγƒ‰(?)
import Data.Functor.Yoneda
import Control.Comonad.Cofree
import Control.Comonad
type Coprogram t = Cofree (Yoneda t)
data Hole = Hole
alone :: Coprogram t a -> t a
alone (_ :< Yoneda f) = f extract
{-# LANGUAGE GADTs, Rank2Types #-}
import Control.Lens
data Chronik f s where
Hexaemeron :: s -> Chronik f s
Inschrift :: f a -> a -> Chronik f s -> Chronik f s
_Chrono :: (f a -> Getting a s a) -> f a -> Lens' (Chronik f s) a
_Chrono getter field f (Hexaemeron s) = fmap (\a' -> Inschrift field a' (Hexaemeron s))
{-# LANGUAGE GADTs, Rank2Types #-}
import Control.Comonad
import Control.Lens.Internal.Context
import Control.Lens
data Chronik s where
Hexaemeron :: s -> Chronik s
Inschriftγ€€:: Context' a (Chronik s) -> Chronik s