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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:41:59+00:00 2026-05-22T18:41:59+00:00

Can I have a class with one member either be float array or array

  • 0

Can I have a class with one member either be float array or array of float array like

type testArr(data: float[],...) =
  member x.data = data
  member x.others = ...
  new( data: float[][],...) = ??? 

I tried to define
type Value = Value1D of float[] | Value2D of float[][], then define type testArr(data: Value,... ), but I then need to rewrite a lot of code for type Value to repeat the array type methods like .Item etc. Alternatively, How do I define type Value inherited from 'a[] but limit the elment type 'a to be float or float[] only?

  • 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-22T18:42:00+00:00Added an answer on May 22, 2026 at 6:42 pm

    I’m not entirely sure why would you need this, but you can define a TestArr class with private constructor and add two static methods to create the two types (float[] and float[][]) that you want to allow:

    type TestArr<'T> private(data:'T[]) = 
      member x.Data = data 
      member x.Others = 42
      static member Array1D(data:float[]) = TestArr(data)
      static member Array2D(data:float[][]) = TestArr(data)
    

    Using an array of arrays always, but with just a single element for the 1D scenario as suggested by Gabe in a comment sounds like a good and simpler alternative.

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

Sidebar

Related Questions

I have a class Person which can have several Homes, each one with one
I'm used to the Java model where you can have one public class per
I have a Class that calls at least one thread. The Class can have
Can a class have a Service Contract attribute and its methods Operation Contract. Or
I have class method that returns a list of employees that I can iterate
You can have different naming convention for class members, static objects, global objects, and
Can an abstract class have a constructor? If so, how can it be used
I have a class that parses very large file (that can't fit in memory)
I have a class SomeClass, which can populate itself from a datarow in it's
I have a class property exposing an internal IList<> through System.Collections.ObjectModel.ReadOnlyCollection<> How can I

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.