Weitere ähnliche Inhalte Ähnlich wie 110617 lt (20) Kürzlich hochgeladen (20) 110617 lt2. monad?
Haskell
monoid
continuation
......
2
3. monad!
( )
Haskell
Maybe Monad Groovy (2009/8/30, Gr )
3
4. example 1
2
S = {2x|x ∈ N, x > 3}
(comprehension)
x 3 ,2 *x
4
6. example 2
import static hr.helix.monadologie.MonadComprehension.foreach
def s(n) {
foreach {
x = takeFrom { 0..n }
guard { x**2 > 3 }
yield { 2*x }
}
}
6
7. example 3
def pythags(n) {
foreach {
z = takeFrom { 1..n }
x = takeFrom { 1..z }
y = takeFrom { x..z }
guard { x**2 + y**2 == z**2 }
yield { [x, y, z] }
}
}
assert pythags(12) == [[3, 4, 5], [6, 8, 10]]
7
11. List (!)
(List<X> X )
List<X> (X a) = { [a] } //
List<Y> (List<X> m, f) =
{ m.inject([]) { r, e -> r + f(e) } } //
// where f s.t. List<Y> f(X x)
// f apply []
11
13. Groovy ?
=> List (Collection)
,
( )
...
13
14. Option - (e.g. null)
Maybe Groovy safe reference “?.”
Either -
Reader - Closure
Writer -
State -
STM -
memoize, ,
AST
14