Yasutaka Higa
y :: B
f :: A -> B
f x = y
=
is a function definitionf x
is a application function f
f x
has type Bdata Delta a = Mono a | Delta a (Delta a)
data
is a data type definition in Haskella
is a type variableMono a
and Delta a (Delta a)
has a type Delta a
>>=
>>=
is an infix function >>= :: (Delta a) -> (a -> Delta b) -> (Delta b)
(Mono x) >>= f = f x
(Delta x d) >>= f = Delta (headDelta (f x))
(d >>= (tailDelta . f))
headDelta
takes first version of DeltatailDelta
takes the rest versionsgenerator x = [1..x]
numberFilter xs = filter isPrime xs
count xs = length xs
numberCount x = count (numberFilter (generator x))
generator x = [1..x]
numberFilter xs = filter even xs
count xs = length xs
numberCount x = count (numberFilter (generator x))
generator x = Mono [1..x]
numberFilter xs = Delta (filter even xs)
(Mono (filter isPrime xs))
count x = Mono (length x)
numberCount x = count =<< numberFilter =<< generator x
*Main> numberCount 1000
Delta 500 (Mono 168)
*Main> numberCountM 10
DeltaM (Delta (Writer (4, ["[1,2,3,4,5,6,7,8,9,10]",
"[2,3,5,7]",
"4"]))
(Mono (Writer (5, ["[1,2,3,4,5,6,7,8,9,10]",
"[2,4,6,8,10]",
"5"]))))