Skip to content

Instantly share code, notes, and snippets.

@xenophobia
xenophobia / nested match-lambda
Created November 20, 2013 04:19
match-lambdaをネストした場合のegison3.0.11の挙動
(define $f
(match-lambda something
{[$x (lambda [$y] (+ x y))]
}))
(test ((f 1) 2))
#|
> 3
|#
Prelude> let f0 = \x -> (x,x)
Prelude> :t f0
f0 :: t -> (t, t)
Prelude> let f1 x = f0(f0 x)
Prelude> :t f1
f1 :: t -> ((t, t), (t, t))
Prelude> let f2 x = f1(f1 x)
Prelude> :t f2
f2
:: t
(define $expl-hash
{| ["key1" "data1"] ["key2" "data2"] ["key3" "data3"] |})
(test expl-hash_"key1")
> "data1"
import Control.Monad.Writer
import Control.Monad.Reader
type FizzBuzz = ReaderT Int (Writer String) ()
tellFizz :: FizzBuzz
tellFizz = do
n <- ask
when (n `rem` 3 == 0) $ tell "Fizz"
import Control.Monad.Writer
import Control.Monad.Reader
type FizzBuzz = ReaderT Int (Writer String) ()
tellFizz :: FizzBuzz
tellFizz = do
n <- ask
when (n `rem` 3 == 0) $ tell "Fizz"
src\Control\Comonad\Representable\Store.hs:112:12:
Couldn't match expected type `w x0 -> v x0'
with actual type `StoreT g0 w0 a0'
In the pattern: StoreT w s
In an equation for `cohoist':
cohoist (StoreT w s) = StoreT (Identity (extract w)) s
In the instance declaration for `ComonadHoist (StoreT g)'
src\Control\Comonad\Representable\Store.hs:112:26:
Couldn't match expected type `StoreT g w a -> StoreT g v a'
{-# Language TypeFamilies, DataKinds, KindSignatures, TypeOperators, UndecidableInstances, ScopedTypeVariables #-}
module Main where
import Data.Type.Natural
import Data.Proxy
data FB = Number Nat | Fizz | Buzz | FizzBuzz
type family Add15 (fb :: FB) :: FB
type instance Add15 (Number n) = Number (n :+ N15)
{-# Language TypeFamilies, DataKinds, KindSignatures, TypeOperators, UndecidableInstances, ScopedTypeVariables #-}
module Main where
import Data.Type.Natural
import Data.Proxy
data FB = Number Nat | Fizz | Buzz | FizzBuzz
type family Mod (m :: Nat) (n :: Nat) :: Nat
type instance Mod (S m) n = MN (S m) n (n :<<= m)
{-# Language TypeFamilies, KindSignatures, UndecidableInstances, DataKinds #-}
module TypeLevelIf where
import Data.Singletons.Types
type family Loop n :: *
type instance Loop a = Loop a
main :: IO ()
main = do
let a = undefined :: If 'True Int (Loop Int)
;; map function
(define $map : [$A $B] ([(A -> B) {A}] -> {B})
(lambda [$fn $xs]
(match xs (list something)
{[<nil> {}]
[<cons $x $rs> {(fn x) @(map fn rs)}]})))
;; Ord type class
(type $Ordering {<Less> <Equal> <Greater>})