How is your operator defined?

By on 8/3/2012 11:49 AM ()

I do not have access to my code/Visual studio for a few days (on vacation) but as far as i can remember i (among other stuff) tried something like:

1
2
type MyJoin =
   static member (==>) ((s1: 'a IObservable,s2,s3), F3 f) = s1.And(s2).And(s3).Then(f)


Should this work?

btw. the code indentation shows up ok in the preview window but is messed up in the posting.

By on 8/3/2012 12:36 PM ()

I found this excellent blog series that explains the innards of operator definition very well:
defining operators in f#
Especially this crucial piece:
"When an operator is found the compiler first try to find a “global” definition at the local scope, if no definition is found then it is assumed as an operator defined at the type of one of the operands."

So i solved it this way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  ///Joins together the result from several Plans
  let Joins (patterns: Joins.Plan<_> List) = Observable.When(patterns |> List.toArray)

  type P1<'a> = P1 of IObservable<'a> with
        static member (==>) (P1(o), F1 f) =
            o.Then(f)

  type P2<'a,'b> = P2 of IObservable<'a> * IObservable<'b> with
        static member (==>) ((P2(o1,o2)), F2 f) = 
            o1.And(o2).Then(f)

///usage
let obs4 = Joins[P2(obs1,obs2) ==> (fun a b -> a + b)  
                 P1(obs3)      ==> (fun a -> a)        ]
By on 11/21/2012 3:29 AM ()

hmm, changing tags does not seem to work.

By on 7/25/2012 3:56 AM ()

Hi,
I corrected the tags on this topic and filed the issue. Thanks for signaling the problem.

By on 7/25/2012 5:23 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper