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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:21:31+00:00 2026-05-30T15:21:31+00:00

I am transforming ASTs and need more than simple pattern matching, thus the unification

  • 0

I am transforming ASTs and need more than simple pattern matching, thus the unification algorithm.

While this is for a .NET project and I know that I could just interoperate with a .NET PROLOG implementation, I only need to embed the unification algorithm; so PROLOG is overkill.

If I could get “Martelli, Montanari: An Efficient Unification Algorithm” written in F# that would be perfect, but I will settle for it any functional language including HASKELL and translate to F#.

  • 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-30T15:21:33+00:00Added an answer on May 30, 2026 at 3:21 pm

    In general, it is a good practice to share your attempts when asking questions on SO. People will not generally give you a complete solution for your problems – just answers when you have specific question or hints how to approach the problem.

    So, I’ll share some hints about the general approach, but it is not a complete solution.
    First you need to represent your AST in some way. In F#, you can do that using discriminated unions. The following supports variables, values and function applications:

    type Expr =
      | Function of string * Expr list
      | Variable of string
      | Value of int
    

    Unification is a function that takes list of expressions to be unified of type (Expr * Expr) list and returns assignments to variables (assigning an expression Expr to a variable name string):

    let rec unify exprs =
      match exprs with 
      // Unify two variables - if they are equal, we continue unifying 
      // the rest of the constraints, otherwise the algorithm fails
      | (Variable s1, Variable s2)::remaining ->
          if s1 = s2 then unify remaining
          else failwith "cannot unify variables"
      // Unify variable with some other expression - unify the remaining
      // constraints and add new assignment to the result
      | (Variable s, expr)::remaining 
      | (expr, Variable s)::remaining  ->
          let rest = unify remaining
          // (s, expr) is a tuple meaning that we assign 'expr' to variable 's'
          (s, expr)::rest
    
      // TODO: Handle remaining cases here!
      | _ -> failwith "cannot unify..."
    

    There are a few cases that you’ll need to add. Most importantly, unifying Function with Function means that you need to check that the function names are the same (otherwise fail) and then add all argument expressions as new constraints to the remaining list…

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

Sidebar

Related Questions

While transforming a document, I need to 'look up' certain node contents in a
Is there any well-known algorithm (or obvious solution) for transforming a list from order
I am transforming an XML into another XML using dom4j. Now I need to
I'm having a difficulty transforming this curl command for my Objective C Code: curl
This code is for transforming from colored to black and white. I tried to
Is there a generalized procedure or algorithm for transforming a SQL subquery into a
I'm transforming an XML document with mimimized br tags like this: <br/> I'm using
This a very similar question as XSL: Transforming xml into a sorted multicolumn html
While transforming some code to lessphp from the classic less code; an incompatibility I
I'm transforming XML to XML using the following XSLT. I need to validate the

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.