Monads/Maybe monad: Difference between revisions

(→‎{{header|Perl 6}}: Add a Perl 6 example)
Line 849:
WAT Nothing Nothing Nothing Nothing
4.285714 0.233333 2.0701966780270626 1.455287232606842 -0.727643616303421</pre>
 
=={{header|Phix}}==
{{trans|Julia}}
Phix has an "object" type which can be an integer or a string, so not entirely un-like Perl.<br>
Here we simply treat all strings or rather non-integers as the "unknown" type.
<lang Phix>function bind(object m, integer f)
return f(m)
end function
function unit(object m)
return m
end function
function times_five(object l)
return iff(integer(l)?l*5:l)
end function
function plus_four(object l)
return iff(integer(l)?l+4:l)
end function
 
procedure test(object l)
printf(1,"%v -> %v\n", {l, bind(bind(l,times_five),plus_four)})
end procedure
test(3)
test("none")</lang>
{{out}}
<pre>
3 -> 19
"none" -> "none"
</pre>
 
=={{header|Racket}}==
7,805

edits