Hi Tamerlin,

First of all the asterisk denotes a tupple. So with the declaration you wrote above, a BinaryNode is a tupple of type 'a and 'a BinaryTree. I guess you would want to write something like this:

1
2
3
4
type 'a BinaryTree =
   | BinaryNode of 'a BinaryTree * 'a BinaryTree
   | BinaryValue of 'a

-Jurgen

By on 7/3/2007 10:26 AM ()

Thanks! At least now I understand the type declaration a bit better :)

Now, I'm just trying to understand why the code to instantiate a BinaryTree isn't working. I'm learning :)

By on 7/3/2007 4:18 PM ()

Tanerlin

I assume that you have figured this out already, but just in case, in response to:

Thanks! At least now I understand the type declaration a bit better :)

Now, I'm just trying to understand why the code to instantiate a BinaryTree isn't working. I'm learning :)

You may have noticed that the the code supplied by Jurgen had one distinct difference to yours:

Your code

1
2
3
type 'a BinaryTree =
   | BinaryNode of 'a * 'a BinaryTree
   | BinaryValue of 'a

Jurgen's Code

1
2
3
type 'a BinaryTree =
   | BinaryNode of 'a BinaryTree * 'a BinaryTree
   | BinaryValue of 'a

The difference is probably just a typo but is important because it relates to the fundamental structure of the binary tree. (That is, a recursive data type consisting of either a node or a tuple of type binary trees)

Hope this helps.

Matt

By on 7/11/2007 9:26 PM ()

Yes, it does help. I think you're right, that it was a typo -- another one of many errors in the Foundations book, apparently. When I looked at that, I was trying to figure out why the sample code read the way it did, not realizing that it was wrong.

Thanks!

Sadly, I'm finding a lot of that in this book. I'm very disappointed, because the book is turning out to be nearly as much impediment as it is help in learning F#, largely due to having a lot of erronoeus code, and a lot of gaps in explanations.

It's a shame, because I'm really growing to like the language overall, though I hate the light syntax with a passion. I detest significant whitespace from my brief stint as a Python victim. Er, developer.

By on 7/16/2007 11:41 AM ()

Hi Tamerlin,

You can program in the "fully qualified" OCaml-like syntax if you wish, using "in" and other delimiters.

Robert has a full errata on his website.

www.strangelights.com/FSharp/Foundations/Default.aspx

Kind regards

Don

By on 7/16/2007 12:08 PM ()

Thanks for the URL. I just wish that Robert had included more info about the fully-qualified syntax, because it would have made it easier for me to learn F#.

He obviously knows the language well, and his enthusiasm for it shows. And I am learning a lot from it, so in the end, it's turning out to be worth the purchase price.

Now I just hope I can find a job that involves .NET so that I can keep using it :)

By on 7/17/2007 8:49 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