Skip to content

Instantly share code, notes, and snippets.

@mausch
Created December 7, 2011 21:31
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/1444750 to your computer and use it in GitHub Desktop.
Save mausch/1444750 to your computer and use it in GitHub Desktop.
type Fmap = Fmap with
static member (?<-) (_, _Functor:Fmap, x:option<_> ) = fun f -> Option.map f x
static member (?<-) (_, _Functor:Fmap, g:_->_ ) = (>>) g
let inline fmap f x = (() ? (Fmap) <- x) f
Then in a separate assembly:
type Fmap with
static member (?<-) (_, _Functor:Fmap, x:list<_> ) = fun f -> List.map f x
Yields:
Warning: Extension members cannot provide operator overloads. Consider defining the operator as part of the type definition instead.
If we ignore the warning and still try to do:
let aa = fmap ((*) 3) [1;2;3]
We get:
Error: No overloads match for method 'op_DynamicAssignment'.
@gusty
Copy link

gusty commented Nov 19, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment