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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:34:23+00:00 2026-05-15T16:34:23+00:00

I’ve been using the following data structure for the representation of propositional logic in

  • 0

I’ve been using the following data structure for the representation of propositional logic in Haskell:

data Prop 
    = Pred  String
    | Not   Prop
    | And   Prop Prop
    | Or    Prop Prop
    | Impl  Prop Prop
    | Equiv Prop Prop
    deriving (Eq, Ord)

Any comments on this structure are welcome.

However, now I want to extend my algoritms to handle FOL – predicate logic.
What would be a good way of representing FOL in Haskell?

I’ve seen versions that are – pretty much – an extension of the above, and versions that are based on more classic context-free grammars. Is there any literature on this, that could be recommended?

  • 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-15T16:34:24+00:00Added an answer on May 15, 2026 at 4:34 pm

    This is known as higher-order abstract syntax.

    First solution: Use Haskell’s lambda.
    A datatype could look like:

    data Prop 
        = Not   Prop
        | And   Prop Prop
        | Or    Prop Prop
        | Impl  Prop Prop
        | Equiv Prop Prop
        | Equals Obj Obj
        | ForAll (Obj -> Prop)
        | Exists (Obj -> Prop)
        deriving (Eq, Ord)
    
    data Obj
        = Num Integer
        | Add Obj Obj
        | Mul Obj Obj
        deriving (Eq, Ord)
    

    You can write a formula as:

    ForAll (\x -> Exists (\y -> Equals (Add x y) (Mul x y))))
    

    This is described in detail in in The Monad Reader article. Highly recommended.

    Second solution:

    Use strings like

    data Prop 
        = Not   Prop
        | And   Prop Prop
        | Or    Prop Prop
        | Impl  Prop Prop
        | Equiv Prop Prop
        | Equals Obj Obj
        | ForAll String Prop
        | Exists String Prop
        deriving (Eq, Ord)
    
    data Obj
        = Num Integer
        | Var String
        | Add Obj Obj
        | Mul Obj Obj
        deriving (Eq, Ord)
    

    Then you can write a formula like

    ForAll "x" (Exists "y" (Equals (Add (Var "x") (Var "y")))
                                   (Mul (Var "x") (Var "y"))))))
    

    The advantage is that you can show the formula easily (it’s hard to show a Obj -> Prop function). The disadvantage is that you have to write changing names on collision (~alpha conversion) and substitution (~beta conversion). In both solutions, you can use GADT instead of two datatypes:

     data FOL a where
        True :: FOL Bool
        False :: FOL Bool
        Not :: FOL Bool -> FOL Bool
        And :: FOL Bool -> FOL Bool -> FOL Bool
        ...
         -- first solution
        Exists :: (FOL Integer -> FOL Bool) -> FOL Bool
        ForAll :: (FOL Integer -> FOL Bool) -> FOL Bool
        -- second solution
        Exists :: String -> FOL Bool -> FOL Bool
        ForAll :: String -> FOL Bool -> FOL Bool
        Var :: String -> FOL Integer
        -- operations in the universe
        Num :: Integer -> FOL Integer
        Add :: FOL Integer -> FOL Integer -> FOL Integer
        ...
    

    Third solution: Use numerals to represent where the variable is bound, where lower means deeper. For example, in ForAll (Exists (Equals (Num 0) (Num 1))) the first variable will bind to Exists, and second to ForAll. This is known as de Bruijn numerals. See I am not a number – I am a free variable.

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

Sidebar

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.