Channels and Isomorphisms
isomorphism n. Some crazy Greek mathematical thing. See the Wikipedia page for the gory details.
TL;DR it's a function, 'a -> 'b
, and its inverse, 'b -> 'a
Isos
In SharpBoomerang, isomorphisms are represented by this type:
1:
|
|
Let's take numerical addition, whose inverse is simply subtraction. Here's an isomorphism representing adding one to a number (and subtracting it):
1:
|
|
See, that's really simple, right? Well sometimes SharpBoomerang can make it even simpler
by inferring the inverse function. Thus, we can simplify the definition further and only
define the 'a -> 'b
function:
1:
|
|
This feature can be very useful when maintaining both the function and its inverse is especially tedious or error-prone. A good example of this is a mapping function:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: |
|
Channels
By themselves, isos aren't that useful, but they become very powerful when you combine them with channels. Here's a more complex example to whet our appetite:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: |
|
Channels and isos are a couple of the powerful tools SharpBoomerang uses to achieve its bidirectionality.
Full name: ChannelsAndIsos.Iso<_,_>
Full name: ChannelsAndIsos.add1
Full name: ChannelsAndIsos.add1_2
type Iso =
private new : unit -> Iso
static member ofFn : expr:Expr<('a -> 'b)> -> Iso<'a,'b>
static member oneWay : fn:('a -> 'b) -> Iso<'a,'b>
Full name: SharpBoomerang.Iso
--------------------
type Iso<'a,'b> = ('a -> 'b) * ('b -> 'a)
Full name: SharpBoomerang.Iso<_,_>
Total, one-to-one isomorphism of a <> b
Given a simple function, `'a -> 'b`, attempts to derive the inverse implicitly
Full name: ChannelsAndIsos.numbers
Full name: Microsoft.FSharp.Core.Operators.failwith
Full name: Microsoft.FSharp.Core.Operators.snd
Full name: ChannelsAndIsos.raw
from SharpBoomerang
Full name: SharpBoomerang.Channel.pipeWith
Creates a PipeChannel with the given initial value.
Full name: ChannelsAndIsos.map
Full name: SharpBoomerang.Channel.map
Maps one channel type onto another using an Iso
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Reads this `IChannel` and calls the passed function with the result.
Writes a`'t` into this `IChannel`.
If this instance represents a read-only channel, then this method must do nothing.