Created
September 24, 2015 15:22
-
-
Save palladin/1fd6d7669e5e6c8b5964 to your computer and use it in GitHub Desktop.
MonadFix in F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let force (value : Lazy<_>) = value.Force() | |
let fix : (Lazy<'T> -> 'T) -> Lazy<'T> = fun f -> | |
let rec x = lazy (f x) in x | |
// Maybe MonadFix | |
let mfix : (Lazy<'T> -> option<Lazy<'T>>) -> Lazy<option<Lazy<'T>>> = fun f -> | |
let rec x = lazy ( match force x with | Some v -> f v | None -> None ) in x |
I think maybe option<'T> is not a good example for mfix and something more lazy like
let mfix : (Lazy<'T> -> seq<'T>) -> Lazy<seq<'T>>
is more easily demonstrable
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe something like this ... ???