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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:47:36+00:00 2026-05-14T03:47:36+00:00

In the following snippet my intention is to convert a System.Object (which could be

  • 0

In the following snippet my intention is to convert a System.Object (which could be an FSharpList) to a list of whatever generic type it is holding.

    match o with
    | :? list<_>              -> addChildList(o :?> list<_>)
    | _                       -> addChild(o)

Unfortunately only list<obj> is ever matched as a list. I would like list<Foo> to also be matched as a list.

For some context, I am trying to traverse an object structure by reflection in order to build a TreeView of the class and its children. Consider the following class:

type Entity = {
    Transform   : Matrix
    Components  : obj list
    Children    : Entity list
}

I would like to build a tree that shows me all the classes that is contained in the entity.
Through reflection, I can obtain all the properties of an object and also their values (The value is important, since I want to display the different elements in a list with the Name property of the element if it has one):

        let o = propertyInfo.GetValue(obj, null)

This value could be a list of some type, but the value return is just a System.Object
I run into problems when trying to convert this object to a list. I am forced to do the following:

        match o with
        | :? list<obj>              -> addChildList(o :?> list<obj>)
        | :? list<Entity>           -> addChildList(o :?> list<Entity>)
        | _                         -> addChild(o)

Here I have to specify exactly the type that I am trying to convert to.
I would really like to write this:

        match o with
        | :? list<_>              -> addChildList(o :?> list<_>)
        | _                       -> addChild(o)

Unfortunately this only ever matches on list< obj >

  • 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-05-14T03:47:37+00:00Added an answer on May 14, 2026 at 3:47 am

    It turns out that either list<'a> or array<'a> can be matched as seq<obj>

        match o with
        | :? seq<obj> -> addChildCollection(o :?> seq<obj>)
        | _           -> addChild(o)
    

    I don’t really care that it is a list. As long as I can iterate over it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following snippet wouldn't compile. With following error: Cannot implicitly convert type 'Container<ChildClass>' to 'Container<BaseClass>'
I have this following snippet in my ANT-buildfile, which reads filenames from a file
I am trying to convert the following JS snippet to CoffeeScript: $(document).ready(function(){ window.setTimeout(function(){ $('#flash').slideUp('slow',
Given following snippet in a view: <style type=text/css> input[type=text] { width: <%: Model.CmsConfiguration.cms_form_width %>px;
The following snippet from RuntimeUtil.java from jlibs guarantees GC that garbage collection is done.
The following snippet is not working for me. Basically I want to check if
Consider the following snippet of code: // get number of sheep in DataTable by
Google optimizer includes the following snippet as part of their conversion code. Unfortunately, the
We have the following snippet. OSStatus createErr = PasteboardCreate(kPasteboardClipboard, &m_pboard); if (createErr != noErr)
I have the following snippet from my code: switch ($extention) { case gif: $src

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.