Anonymous user
Talk:Monads/List monad: Difference between revisions
→F# example
Line 75:
</lang>
:The task requirement is Construct a List Monad by writing the 'bind' function and the 'pure' (sometimes known as 'return') function for that Monad (or just use what the language already has implemented). The example just uses what the language already has implemented. 'let x=something" means refer to something.bind as x. In F# List is a ListMonad. F# uses yield rather than 'mu' 'pure' or 'return' see [https://fsharpforfunandprofit.com/posts/computation-expressions-builder-part1/#introducing-yield introducing yield].--[[User:Nigel Galloway|Nigel Galloway]] ([[User talk:Nigel Galloway|talk]]) 15:20, 14 September 2021 (UTC)
::Hi. The way to implement new monads in F# is clearly with computation expressions [https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/computation-expressions#creating-a-new-type-of-computation-expression]. You'll note that the table of functions on that page includes Bind and Return. We just need to fill in the right implementation for those functions. For the list monad it's straightforward, as the example I've given shows.
::
::Re "yield", as you can see from Microsoft docs link above, Return is very much available and built into the interface of F#'s computation expressions, and there's no reason to prefer the alternative yield here, especially since the problem asks for 'return'.
|