You could do :

1
2
3
4
 

let distances = matrix <| Seq.map (fun p -> Seq.map (distance p) coordinates) coordinates

Edit : but you would have to define distance as a curried function like this :

1
2
3
4
 

let distance (x1,y1) (x2,y2) = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) 

An alternative using comprehensions :

1
2
3
4
 

let distances = matrix [ for p in coordinates -> [ for p' in coordinates -> distance p p' ] ]
By on 5/27/2010 2:02 PM ()

Thank you. I used your last suggestion and it works beautifully. I had to make one change though for the compiler not to report a problem. It wanted me to put parentheses around the arguments for distance function:

1
2
let distances = matrix [ for p in coordinates -> [ for p' in coordinates -> distance(p, p') ] ]
By on 5/27/2010 3:39 PM ()

Your version of the code is indeed the correct one for the distance function you provided, which is defined in tupled form (with comma separated arguments or more precisely with a single tuple argument). I, however, had to define it in curried form (with whitespace separated arguments) in order for my first suggestion to work, hence the compiler complaining when mixing my code and your version of distance.

You can see [link:lorgonblog.spaces.live.com] for an introduction on these topics.

By on 5/27/2010 5:28 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