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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:50:01+00:00 2026-05-25T15:50:01+00:00

I am trying to design an AST for a decision logic table. One of

  • 0

I am trying to design an AST for a decision logic table. One of the things I would like to be able to do with the discriminated union that represents my AST is transform parts of it for different reasons. For clarity I will give you an example

Decision Logic Table

@ VAR = 10 ;Y;

The above can be read as there is one rule and the condition VAR = 10 enters this rule with a Y entry.

Abstract Syntax Tree Definition (simplified for this example)

 type expression = 
     | Value of double
     | Variable of string 
     | Equality of expression * expression

type entry =
    | Entry of string

type entries =
    | Entries of entry list

type conditional =
    | ConditionEntries of expression * entries

type condition
    | Condition of expression * string

type rule = 
    | Rule of condition list

Rendered (before transform)

ConditionEntries(
    Equality(
        Variable("VAR"), 
        Value(10.0)), 
    Entries(["Y"]))

Rendered (after transform)

Rule(
    Condition(
        Equality(
            Variable("VAR"),
            Value(10.0)
        ),
        Entry("Y")
    )
)

Now what I would like to do is transform the above tree to expand the rules that are represented in the entries. My thinking was I could use a recursive function and pattern-matching to do this but I am having a little trouble wrapping my head around it right now.

I guess in essence what I am trying to do is whenever I see a ConditionEntries node, I want to emit a new Rule for every string in the Entries list where the Condition is combined with the Entry. Does that make any sense?

Thanks in advance for any advice.

p.s. I haven’t quite tried to compile the above example, so please forgive any grammatical errors.

  • 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-25T15:50:02+00:00Added an answer on May 25, 2026 at 3:50 pm

    Hmm, based on your AST, which is awfully broken up, here is a tranform function which produces the output from input you desire (though it’s not recursive, just uses List.map with some pattern matching. expression is your only recursive type but it doesn’t look like you want to process it recursively?):

    let ex1 =
        ConditionEntries(
            Equality(
                Variable("VAR"), 
                Value(10.0)), 
            Entries([Entry("Y")]))
    
    let ex2 =
        ConditionEntries(
            Equality(
                Variable("VAR"), 
                Value(10.0)), 
            Entries([Entry("X");Entry("Y");Entry("Z")]))
    
    let transform ces =
        match ces with
        | ConditionEntries(x, Entries(entries)) ->
            entries
            |> List.map (function Entry(entry) -> Condition(x, entry))
    
    
    //FSI output:
    > transform ex1;;
    val it : condition list =
      [Condition (Equality (Variable "VAR",Value 10.0),"Y")]
    > transform ex2;;
    val it : condition list =
      [Condition (Equality (Variable "VAR",Value 10.0),"X");
       Condition (Equality (Variable "VAR",Value 10.0),"Y");
       Condition (Equality (Variable "VAR",Value 10.0),"Z")]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to design support for recurring events (like you would see in
I'm trying to design a data model that denotes one user being the friend
I am trying to design my URLs so that I can get only one
i'm trying to design interface like this one http://www.softpedia.com/screenshots/FlashFXP_2.png i'm using the QT design
I am trying to design a table type structure that contains rows and cells.
I'm trying to design a homepage for an MVC site that has two different
I am trying to design a layout so that I can change the views
I'm trying to design a font selection tool where a user can select one
I'm trying to design some bookmarklets right now, that connect back to a server
I am trying to design a feature in my application for the iPhone that

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.