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
data Nat = Zero | Succ Nat | |
data SNat (n :: Nat) where | |
SZero :: SNat 'Zero | |
SSucc :: SNat m -> SNat ('Succ m) |
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
type family NIntArrow (a :: Nat) | |
type instance NIntArrow 'Zero = Int | |
type instance NIntArrow ('Succ n) = Int -> NIntArrow |
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
addN :: SNat nat -> NIntArrow nat | |
addN n = addN' n 0 | |
where | |
addN' :: SNat nat -> Int -> NIntArrow nat | |
addN' SZero acc = acc | |
addN' (SSucc n') acc = \x -> addN' n' (acc+x) |
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
{-# Language FlexibleInstances, ScopedTypeVariables #-} | |
class AddNType t where | |
adds :: Int -> t | |
instance AddNType Int where | |
adds = id | |
instance AddNType t => AddNType (Int -> t) where | |
adds n = \m -> (adds (n+m) :: t) | |
addN :: AddNType t => t | |
addN = adds 0 |
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
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE QuasiQuotes #-} | |
{-# LANGUAGE TypeSynonymInstances #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE OverlappingInstances #-} | |
import Control.Comonad | |
import Language.Haskell.Codo | |
type Option = String |
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
config :: Config | |
config = [ooLikeSyntax| | |
builder <- defaultBuilder | |
builder#profile | |
builder#goFaster | |
builder#extract|] |
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
> (define $onetwo {1 @onetwo 2}) | |
> (test (match onetwo (list integer) {[<join _ _> <Ok>] [_ <Ko>]})) | |
> <Ok> |
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
import Prelude hiding (head, tail) | |
import Control.Comonad | |
data Stream a = St {head :: a, tail :: Stream a} | |
instance Functor Stream where | |
fmap f s = St (f (head s)) (fmap f (tail s)) | |
instance Comonad Stream where | |
extract = head |
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
import Prelude hiding (head, tail) | |
import Control.Comonad | |
data Stream a = St {head :: a, tail :: Stream a} | |
instance Functor Stream where | |
fmap f s = St (f (head s)) (fmap f (tail s)) | |
instance Comonad Stream where | |
extract = head |
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
{- http://d.hatena.ne.jp/majiang/20130602/1370188046 -} | |
-- return, >>= は所与ってことにする | |
s :: a -- 0 | |
ms :: m a -- 1 | |
f :: a -> b -- 4 | |
mf :: m (a -> b) -- 6 | |
f s :: b | |
return (f s) :: m b |