Created
May 10, 2018 19:53
-
-
Save mrkaspa/553fe794cbd1a774324d6fbfc9bba395 to your computer and use it in GitHub Desktop.
Functors in 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 SumFunctor<'T> = { | |
sumFn : 'T -> 'T -> 'T | |
diffFn : 'T -> 'T -> 'T | |
} | |
let createSumFunctor monoidOp negMonoidOp = | |
{ | |
sumFn = monoidOp | |
diffFn = negMonoidOp | |
} | |
let sumable { sumFn = sumFn } a = | |
sumFn a a | |
let sum1 (a : float) = | |
let s : SumFunctor<float> = createSumFunctor (+) (-) | |
sumable s a | |
let sum2 (a : int) = | |
let s : SumFunctor<int> = createSumFunctor (+) (-) | |
sumable s a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment