Haskell

Dyad

Maarten Fokkinga の Dyads。使い道は謎。 {-# LANGUAGE Arrows, MultiParamTypeClasses, FunctionalDependencies, TypeOperators #-} module Main where import Prelude import Control.Arrow import qualified Control.Category as Cat import Control.Mon…

Template Haskellで遊ぶ

Ross Patersonの論文に面白いデータ構造「homogeneous functions」があって: type Pair a = (a, a) data BalTree a = Zero a | Succ (BalTree (Pair a)) deriving (Show) -- the homogeneous functions data Hom a b = ( a -> b ) :&: Hom (Pair a) (Pair b…

return2について

mclh46さんの記事のreturn2についていろいろと考えました。そして「つまりreturn2は二択returnのことですね」と勝手に結論を付けました。ならば最近見ているControl.Arrowの中にもこういう選択的な機能をサポートする関数があります。 (|||) :: a b d -> a c…

FizzBuzzをArrowで

元ネタ: FizzBuzz問題から学ぶモナド FizzBuzzをモナドで - トウフ日記 とにかく書いてみた。もう何番煎じ? import Control.Arrow fizzbuzz = mapM_ (putStrLn . ((fizz &&& buzz >>> chain) &&& nofb >>> chain)) where fizz x | x `mod` 3 == 0 = "Fizz"…