Talk:Monads/List monad: Difference between revisions

m
→‎F# example: Expand with Pythagorean triple example.
m (→‎F# example: Expand with Pythagorean triple example.)
Line 56:
 
It might be good if someone more familiar with the wiki and with F# can confirm that this change is appropriate. NB I have checked that this code works, but the syntax highlighting here is getting confused.
 
More:
 
<lang fsharp>
type ListMonad() =
member o.Bind( (m:'a list), (f: 'a -> 'b list) ) = List.concat( List.map f m )
member o.Return(x) = [x]
member o.Zero() = []
let list = ListMonad()
 
let pyth_triples n = list { let! x = [1..n]
let! y = [x..n]
let! z = [y..n]
if x*x + y*y = z*z then return (x,y,z) }
printf "%A" (pyth_triples 100)
</lang>
Anonymous user