Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8434821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:45:45+00:00 2026-06-10T06:45:45+00:00

I have a simple type like this: /// <summary> /// An attribute consists of

  • 0

I have a simple type like this:

/// <summary>
/// An attribute consists of a key and all possible values.
/// </summary>
type IAttribute<'a when 'a: comparison> =
    abstract Key: string
    abstract Values: seq<'a>

From this definition I create implementations like so:

let numericAttribute values =
    { new IAttribute<float> with
        member this.Key = "Numeric"
        member this.Values = values }

let enumerationAttribute values =
    { new IAttribute<string> with
        member this.Key = "Enumeration"
        member this.Values = values }

Examples:

let numAttr = numericAttribute [| 1.0; 4.0; 6.0; 20.0; 70.0 |]
let enAttr = enumerationAttribute [| "val1"; "val2"; "val3" |]

Now I can create instances:

let num1 = new AttributeInstance<float>(numAttr, 4.0)
let num2 = new AttributeInstance<float>(numAttr, 6.0)
let en1 = new AttributeInstance<string>(enAttr, "val1")

AttributeInstance is a type that is just a tuple of a specific attribute type and a value compatible with that attribute type.

I want a simple Tree along the lines of this:

type Tree<'a when 'a: comparison> =
| Leaf of 'a
| SubTree of AttributeInstance<'a> * seq<Tree<'a>>

My problem is that at different levels of the tree I want to be able to have different types. At one level I want to have a sub tree where the attribute is en1, and at the next level I want to be able to have num1 (or num2).

Can someone help me generalize or rethink this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:45:46+00:00Added an answer on June 10, 2026 at 6:45 am

    The problem is if you try to write something like

    |Subtree of 'a * seq<Tree<'b>>
    

    'b ends up being a new type which could create something like an infinite chain of types which the compiler doesn’t support.

    One way to do this can be to wrap the possible types in a Union – Something like

    type Element = 
        |....
    

    and then your tree becomes

    type Tree =
    | Leaf of Element
    | SubTree of AttributeInstance<element> * seq<Tree>
    

    alternatively, you can have a multi generic tree – something like

    type Tree<'a,'b,'c,'d> =
    | Leaf1 of 'a
    | Leaf2 of 'b
    ...
    | SubTree of AttributeInstance<'a> * seq<Tree<'a,'b,'c,'d>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple ajax call like this: $.ajax({ url: u, type: POST, dataType:
For me json is lowercase. So I have defined simple type like this: public
i have this simple type from an external webservice: <xsd:element name=card_number maxOccurs=1 minOccurs=1> <xsd:simpleType>
Possible Duplicate: c++ virtual function return type I have a simple but confusing question
I'm a beginner in jQuery area and I have simple question like this :
I have this simple datatable : type (string) | cnt (int) _____________________________________ aaa 1
I have a simple form that looks like this: class SettingsForm(forms.ModelForm): theme = forms.CharField(required=True,
I have a simple form in Django that looks like this: class SettingForm(forms.Form): theme
I have a record type like this: type Rule = {extension: string seq; subdir:
I have simple document with this mapping: 'product': { 'properties': { 'name': { 'type':

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.