Skip to content

Instantly share code, notes, and snippets.

@mausch
Created March 25, 2014 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mausch/9769943 to your computer and use it in GitHub Desktop.
Save mausch/9769943 to your computer and use it in GitHub Desktop.
// broken fmap for option
let fmap f =
function
| None -> None
| Some a ->
let b = f a
if box b = null then None else Some b
// second functor law, see http://www.haskell.org/haskellwiki/Functor
let fmapL p q = fmap (p << q)
let fmapR p q = fmap p << fmap q
let test (p: string -> string) (q: string -> string) (x: string option) = fmapL p q x = fmapR p q x
test (fun _ -> "") (fun _ -> null) (Some "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment