package require punk #https://www.youtube.com/watch?v=26jVysJHB-s #based on Monads in Python: Why and How? #some function timer proc xxxpipet {subcommand} { return [list % val $subcommand |sub> { if {![info exists input]} { set input "" } else { set input } } |input> {clock micros} |start> {{*}$sub {*}$input} |res> {expr [clock micros] - $start} |t> {list $res $t} \ {clock micros} |start> {{*}$sub {*}$input} |res> {expr [clock micros] - $start} |t> {list $res $t} {expr {$x + 1}} {expr {$x + 2}} .= {{*}[pipet $::fast] $data} |d@0,t@1> {{*}[pipet $::slow] $d} |d@,t2@> {{*}[pipet $::slow2] $d} |d@,t3@> {list $d [expr {$t + $t2 + $t3}]} #method 2 - abstract away the extraction and summation in a bind function # x2, t = bind(bind(fast(1), slow), slow2) # % bind=% {list $vt $f} |v@0/0,t@0/1> {{*}$f $v} |r2@,t2@> {list $r2 [expr {$t + $t2}]} {{*}$f $v} |r2@,t2@> {list $r2 [expr {$t + $t2}]} \ {clock micros} |start> {{*}$sub {*}$input} |res> {expr [clock micros] - $start} |t> {timedvalue new $res $t} {$o bind o_slow} \ |o> {$o bind o_slow2} puts "tvresult value: [$tvresult value]" puts "tvresult time: [$tvresult time]" #timedvalue class is a monad