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 8822047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:00:17+00:00 2026-06-14T06:00:17+00:00

For a project of mine, I need a list that can carry multiple types,

  • 0

For a project of mine, I need a list that can carry multiple types, and I don’t want to do any casting, so I’ve tried using obj lists. Here’s some example code to show something that should work, but for some reason doesn’t:

type Fruit() =
  member this.Kind = "I'm a tasty fruit!"

type Apple() =
  inherit Fruit()
  member this.Kind = "I'm a crispy apple!"

type Cherry() =
  inherit Fruit()
  member this.Kind = "I'm a juicy cherry!"


> (new Fruit()).Kind
val it : string = "I'm a tasty fruit!"

... // And so on; it works as expected for all three fruits

> let aFruit = [new Fruit()]
val aFruit : Fruit list = [FSI_0002+Fruit]

> aFruit.Head.Kind                          // Works just fine
val it : string = "I'm a tasty fruit!"

> let fruits : obj list = [new Fruit(); new Apple(); new Cherry]
val fruits : obj list = [FSI_0002+Fruit; FSI_0002+Apple; FSI_0002+Cherry]

> fruits.Head                               // Okay, so we can extract items just fine. It also kept the property!
val it : obj = FSI_0002+Fruit {Kind = "I'm a tasty fruit!";}

> it.Kind                                   // This doesn't work. Why? What am I missing?
 error FS0039: The field, constructor or member 'Kind' is not defined
  • 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-14T06:00:19+00:00Added an answer on June 14, 2026 at 6:00 am

    The problem is that it has type obj as the list is an obj list and obj has no .Kind member. You can use the parent type – like

    let fruits : Fruit list = [new Fruit(); new Apple(); new Cherry()];;
    
    val fruits : Fruit list = [FSI_0003+Fruit; FSI_0003+Apple; FSI_0003+Cherry]
    

    and then access it with:

    fruits.Head.Kind;;
    val it : string = "I'm a tasty fruit!"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a project of mine I need to do multiple calls to a (remote)
I need to import the RSyntaxTextArea to a project of mine, but i can't
Developing a project of mine I realize I have a need for some level
In a small project of mine I've came across the need of a collapsible
Background Currently in a project of mine I am using jQuery autocomplete for a
In a linguistic project of mine I need to use symbols not contained in
This is for a little pet project of mine. I want to write a
As part of a pet project of mine, I need to test the performance
In a project of mine here I have a class that implements four interfaces:
A collegue of mine forked my project and we want to incorporate his changed

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.