I want to define "relations", but defined as functions to Identity<'a>, seq<'a> and Option<'a>.
I have never defined overloaded operators in F#.
It would be sort of nice to use "+" !
open FSharpPlus.Data
type Relation =
// ('a -> Identity<'b>) -> ('b -> 'c) -> ('a -> 'c)
static member (+) (f,g) =
fun a -> g ((f a) |> Identity.run)
// ('a -> #seq<'b>) -> ('b -> #seq<'c>) -> ('a -> seq<'c>)
static member (+) (f , g ) =
fun a -> seq {
for b in f a do
yield! g b
}
// ('a -> seq<'b>) -> ('b -> Identity<'c>) -> ('a -> seq<'c>)
static member (+) (f,g) =
fun a -> seq {
for b in f a do
yield Identity.run (g b)
}
this compiles...
then I try to use it and;
member x.foo () =
let f1 : int -> Identity<int> = fun x -> Identity x
let f2 : int -> seq<int> = fun x -> Seq.singleton x
let x = f2 + f1
()
I get:
FS0043 Expecting a type supporting the operator '+' but given a function type. You may be missing an argument to a function.
am I doing something silly? (yes!)