2

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!)

Fyodor Soikin
  • 78,590
  • 9
  • 125
  • 172
MrD at KookerellaLtd
  • 2,412
  • 1
  • 15
  • 17
  • 1
    Possible duplicate of [Overloading + operator in F#](https://stackoverflow.com/questions/7695393/overloading-operator-in-f) – scrwtp Sep 25 '18 at 19:02
  • 1
    Check out this answer in the linked thread https://stackoverflow.com/a/8376001/679898 from Mr. FSharpPlus himself, though doing so might cost you a few sanity points ;) – scrwtp Sep 25 '18 at 19:03
  • thanks I'll look at these...Ive been tryiing to get one of them to work already – MrD at KookerellaLtd Sep 26 '18 at 16:45

0 Answers0