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

  • Home
  • SEARCH
  • 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 8604085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:28:57+00:00 2026-06-12T02:28:57+00:00

I am a F# newbie. I have 2 classes, Base and Derived. Base has

  • 0

I am a F# newbie.

I have 2 classes, Base and Derived.

Base has a number of methods. Derived inherits some methods as they are and some it overrides. Derived class also introduced new methods.

I have a set of objects, some are Base and some are Derived.

There is a list of 2 elements tuples, second element of the tuple being a method of a polymorphic hierarchy.

Let’s consider my program that reads input and for each input goes through the list applying the first element of each tuple (a predicate) to the input.

If the predicate is true, then it invokes the second element of the tuple on an object that could be Base or Derived (depending, again, on the value of the first element of the tuple).

It’d be nice to a single list of such tuples, instead of 2 lists as it is now(one for Base and one for Derived). Is this possible?

Assume Base class defines method1 and method2.

Assume Derived class defines (overriding) method2 and method4.

let predList = 
  [(predicate1, Base.method1);
  (predicate2, method2);
  (predicate4; Derived.method4) 
  ... 
]

 while ... do
     let input = ReadInput
     if IsBase(input)
         then 
             let method = List.Find matchingPredicate predList
             let baseObj = ChooseBaseObject(input)
             baseObj.method  // ????
         else 
             let method = List.Find matchingPredicate predList
             let derivedObj = ChooseDerivedObject(input)
             derivedObj.method  // ????

With such code, a given input that satisfies predicate2 may trigger a call to Derived.method2 or Base.method2 depending on what IsBase(input) returns.

  • 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-12T02:28:59+00:00Added an answer on June 12, 2026 at 2:28 am

    The simplest thing is maybe wrapping your method‘s into a group of standalone functions:

    let wrap_method1 (x :Base) = x.method1()
    let wrap_method2 (x :Base) =
       match x with
       | :? Derived as xd -> xd.method2()
       | _ -> x.method2()
    let wrap_method4 (x :Base) =
       match x with
       | :? Derived as xd -> xd.method4()
       | _ -> ()
    
    // use
    let predList = 
        [(predicate1, wrap_method1);
        (predicate2, wrap_method2);
        ... ]
    
    while ... do
        let input = ReadInput
        let method = List.Find matchingPredicate predList
        method input
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie Python question. I have a class that inherits from several classes, and some
Newbie question. I have two c# classes - a code class (say, CodeClass) and
Slight newbie question. I have a base class for payments. All share the same
I have a newbie WPF question. Imagine my user control has a namespace declaration
I'm brand new to SQL Server 2008, and have some newbie questions about the
I have defined classes: public class Parent : IParent { public string ParentText {
Complete rails newbie trying to get started. I have two classes, Ingredient, and Unit.
I have the following basic classes (cut down for this question): public class Parent
newbie doing Java homework here. I have one class named Album which contains the
I am newbie to SOA though I have some experience in OOAD. One of

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.