I think you either want

let c = Child1 "Tony"
let p = Parent2 (c)

where both are values, or

let cf = Child1
let pf s = Parent2 (cf s)

where both are functions, but I'm not sure what you intended.

By on 6/12/2009 5:56 AM ()

Thanks for the response. You're right in that I should have put the string in. This doesn't solve the general problem though.

Basically I want to be able to cast a Child1 type to a Child type automatically so that it is a valid type for Parent to accept. Does F# support this capability?

Cheers

By on 6/12/2009 7:34 AM ()

I am still unclear what you are asking. There is no "Child1" type per se, that's just one union case of the "Child" type. In the code

let c = Child1 "Tony"the type of 'c' is 'Child' (not 'Child1').

By on 6/12/2009 8:33 AM ()

Thanks for bearing with me on this. I'll try and give you a clearer example of what I am trying to achieve.

I am implementing a grammer and interpreter. Here is a small subset of the grammer:

type Relation =

| Inheritance of Term * Term

| Similarity of Term * Term

and Term =

| Word of Word

| Compound_term of Compound_termT

and Compound_termT =

| ExtSet of Term list

| IntSet of Term list

and Word = string

I want to be able to use statements such as:

let test = Inheritance(Word("bird"), IntSet[Word("living"), Word("flyer")])

This creates a type match error. The Relation type expects two terms. The 'Word' case works as expected but the compound_term case generates the error.

Does that give you a better idea of my goal?

Thanks

By on 6/12/2009 10:53 AM ()

Ok, there are various confounding issues in your code, namely that lists need semicolons (not commas) to delimit elements, and the re-use of the identifier 'Word' with two meanings. The code below shows about as close as you can get.

type Relation =
| Inheritance of Term * Term
| Similarity of Term * Term

and Term =
| Word of WordType
| Compound_term of Compound_termT

and Compound_termT =
| ExtSet of Term list
| IntSet of Term list

and WordType = string

//let test = Inheritance(Word("bird"), IntSet[Word("living"); Word("flyer")]) // does not work

let test = Inheritance(Word("bird"), Compound_term(IntSet [Word("living"); Word("flyer")])) // works

let CT = Compound_term
let test2 = Inheritance(Word("bird"), CT(IntSet [Word("living"); Word("flyer")])) // works

By on 6/12/2009 1:20 PM ()

It must be really nice when you know what you're doing!

Thank you very much. That was what I needed.

By on 6/12/2009 1:34 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