Your code is not being displayed properly, so it's hard to know exactly what's wrong. However this code works for me:

1
2
3
4
5
6
7
8
9
10
11
12
type Tree<'a when 'a : comparison> = 
| Node of Tree<'a> * 'a * Tree<'a> 
| Empty 
  member this.insert (x: 'a) = 
    match this with 
    | Empty -> Node(Empty, x, Empty) 
    | Node(l, v, r) when x < v -> Node(l.insert(x), v, r) 
    | Node(l, v, r) when x > v -> Node(l, v, r.insert(x)) 
    | Node(_) -> this 

let testTree = Node(Empty, 1, Empty) 

What environment are you using?

By on 12/30/2010 11:13 AM ()

Thanks for the reply, and thanks for making sense of my careless post. I am using f# 2.0 with MonoDevelop 2.4.1 on mono 2.8.1 on a mac. Your snippet is the same code as I intended to present.

I now find that if I cut and paste the whole sample in my interactive window, the snippet works. If I enter the Tree definition into the interpreter, then put the testTree assignment in separately, it crashes as before.

I haven't tried fsi in a terminal window yet, so I don't know if this behaviour is something to do with Monodevelop or fsharp.

By on 12/30/2010 2:06 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