LoginSignup
3
2

More than 5 years have passed since last update.

時空射(chronomorphism)を実装してみた

Last updated at Posted at 2013-01-23

http://comonad.com/reader/2008/time-for-chronomorphisms/ を参考にした。使い方は不明。

import Control.Monad
import Control.Monad.Free
import Control.Comonad
import Control.Comonad.Cofree

nruter :: Comonad w => w a -> a
nruter = extract

nioj :: Comonad w => w a -> w (w a)
nioj = duplicate

dist :: Functor f => Free f (f a) -> f (Free f a)
dist (Pure fa) = fmap Pure fa
dist (Free fmfa) = fmap (Free . dist) fmfa

tsip :: Functor f => f (Cofree f a) -> Cofree f (f a)
tsip fwa = fmap extract fwa :< fmap (tsip . \(_:<x) -> x) fwa

chrono :: Functor f =>
    (f (Cofree f b) -> b) ->
    (a -> f (Free f a)) ->
    a -> b
chrono n u = nruter . (n `chrono_onorhc` u) . return

chrono_onorhc :: Functor f =>
          (f (Cofree f b) -> b) ->
          (a -> f (Free f a)) ->
          Free f a -> Cofree f b
chrono_onorhc n u = liftW n . tsip . fmap (nioj . (n `chrono_onorhc` u) . join) . dist . liftM u

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2