Created
December 7, 2011 21:31
-
-
Save mausch/1444750 to your computer and use it in GitHub Desktop.
Testing type classes from http://www.nut-cracker.com.ar/index.php/typeclasses-for-fsharp
This file contains 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
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'. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Post moved to http://nut-cracker.azurewebsites.net/typeclasses-for-fsharp/