Hide this comment

As you have no traits, an alternative is write your sum-type in this way:

1
2
3
4
5
6
7
8
9
type pexpr = pos * expr
and expr =
   | Var of pos * string
  

| IntLit of pos * int
  

| Plus of pos * pexpr * pexpr 

You may want to define also some active-patterns to simplify your code.

Laurent.

By on 10/6/2009 9:11 AM ()Reply
Hide this comment

By the way, there was a similar discussion here: [link:cs.hubfs.net]

Laurent.

By on 10/6/2009 9:14 AM ()Reply
Hide this comment

Thanks! Those answers were both very helpful. :-)

By on 10/7/2009 1:08 AM ()Reply
Hide this comment

F# doesn't support traits. ([link:cs.hubfs.net])

But, you could probably use interfaces and objects to do what you need (like you do in the scala example) rather than types, although it looks to me like the ML style types are cleaner.

See here for the syntax on objects ([link:msdn.microsoft.com])

By on 10/6/2009 7:43 AM ()Reply
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

Logging in...