tpetricek / tomasp.net

Source code for my web site and blog - yet another remake!
26 stars 19 forks source link

F# Overview (IV.) code doesn’t compile #40

Open daveyostcom opened 1 year ago

daveyostcom commented 1 year ago

F# Overview (IV.) - Language Oriented Programming

type M<'a> = option<'a>

let bind f d = 
  match d with
   | None -> None
   | Some(v) -> f v
let result v = Some(v)
let delay  f = f()

type MaybeBuilder() =
  member x.Bind(v, f) = bind v f
  member x.Return(v)  = result v
  member x.Delay(f)   = delay f 
  member x.Let(v, f)  = bind (result v) f   <–––  error

let maybe = MaybeBuilder()

The error on result v is

This expression was expected to have type     ''a -> 'b option' but here has type     ''c option'

daveyostcom commented 1 year ago

bind f d should be bind d f