Skip to content

Instantly share code, notes, and snippets.

@yodiz
Created May 28, 2024 16:34
Show Gist options
  • Save yodiz/f1e77d6e1bbc7a19c4e45c9e1f9b2b5b to your computer and use it in GitHub Desktop.
Save yodiz/f1e77d6e1bbc7a19c4e45c9e1f9b2b5b to your computer and use it in GitHub Desktop.
#r "nuget:FSharpPlus"
open FSharpPlus
type Transaction<'T> = |Transaction of (unit -> 'T)
with
static member Return (x: 'T) : Transaction<'T> = Transaction.Transaction (fun () -> x)
static member (>>=) (x: Transaction<'T>, f: 'T -> Transaction<'U>) : Transaction<'U> =
match x with Transaction.Transaction fn -> fn () |> f
//For delayed
static member TryWith (computation: unit -> Transaction<'T>, catchHandler: exn -> Transaction<'T>) : Transaction<'T> =
failwithf ""
static member TryFinally (source: Transaction<'T>, f: unit -> unit) : Transaction<'T> =
failwithf ""
//Works
let c arg : Transaction<string> = monad.strict {
return arg
}
//Works
let d = monad.strict {
let! a = c "A"
let! b = c "B"
return a+b
}
//unknown(1,1): error FS0073: internal error: Undefined or unsolved type variable: ^_?124161
let e = monad {
let! a = c "A"
let! b = c "B"
return a+b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment