Talk:Monads/List monad: Difference between revisions

 
(One intermediate revision by the same user not shown)
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.
 
::You do have a point that List Comprehensions are equivalent to the list monad. So maybe any discussion of implementing monads using computation expressions belongs on another page where it's actually essential to the functionality, say [[Monads/Writer monad]]. But by the same token, list comprehension examples surely belong at [[List comprehensions]]. After all, this is about showing off the specific language feature that the task specifies, isn't it? And this task is about defining new monads.
 
::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'.
Anonymous user