This does'nt buy you much, but you could define your own operator to join two functions returning bool using an and operation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 

>let (&&+) f g x = (f x) && (g x)

let f x = x>1
let g x = x<3

let h = f &&+ g;;


val ( &&+ ) : ('a -> bool) -> ('a -> bool) -> 'a -> bool
val g : int -> bool
val f : int -> bool
val h : (int -> bool)

> h 1;;
val it : bool = false
> h 2;;
val it : bool = true
> h 3;;
val it : bool = false
By on 1/29/2009 8:36 PM ()

Hmm, yea I guess that works, perhaps the way i aws doing it was already the most elegant, for some reason I was just thinking there was a way to do it with only composition, reverse composition, and/or the forward pipe operator.

By on 1/30/2009 8:02 AM ()

Hmm, yea I guess that works, perhaps the way i aws doing it was already the most elegant

Well, you could drop the parens, because function-calls bind more tightly than logical operations:

1
2
3
let f x = x>1
let g x = x<3
let h x = f x && g x

See Precedence and Operators in the F# Draft Language Specification.

By on 1/30/2009 1:51 PM ()
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