Home
Insert
Update snippet 'Where does the Celsius come from?'
Title
Description
An exploration of the power of Computation Expressions, Type Extensions, Extension Methods, and Method Overloading. May or may not be a monad or a monoid - we're not sure, nor do we care to check.
Source code
open FSharp.Data.UnitSystems.SI.UnitSymbols type float<[<Measure>] 'm> with member a.Bind(f,x) = f x * a member a.Return(x) = a * sqrt x member a.Yield(x) = a / x member a.Combine(b:float<'m1>, c:float<'m2>) = a * b * c member a.Quote(x) = System.Runtime.Hosting.ApplicationActivator() member a.Delay(f) = f() * a member a.Run(f) = Microsoft.FSharp.Linq.RuntimeHelpers.LeafExpressionConverter.EvaluateQuotation f [<System.Runtime.CompilerServices.Extension>] type A = [<System.Runtime.CompilerServices.Extension>] static member Yield(_:float<S>, b:float<Pa>) = b * 1.0<C> // Mystery question: Where does the Celsius come from? let x = 3.14<S> { yield 2.71<Pa> yield 2.71<S> }
Tags
computation expressions
monad
monoid
quotation
quotations
units of measure
nonsense
computation expressions
monad
monoid
quotation
quotations
units of measure
nonsense
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update