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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:06:01+00:00 2026-06-15T01:06:01+00:00

I am having trouble with the Mod operator in Haskell Its inferring the wrong

  • 0

I am having trouble with the Mod operator in Haskell Its inferring the wrong type based on what I have. Mod is at the bottom of eval. I am new to Haskell and am making an AST with expr for class. Here is the code I have so far. I am sure its a simple fix but cant seem to get it.

data Expr = Add Expr Expr
      | Sub Expr Expr
      | Mult Expr Expr
      | EqualTo Expr Expr
      | GreaterThan Expr Expr
      | LessThan Expr Expr
      | Mod Expr
      | NotEqual Expr Expr

      | Const Integer
      | VarName String
      | TrueE
      | FalseE
  deriving (Show,Eq) 


eval :: Expr -> [(String, Integer)] -> Integer
eval (Add e1 e2) env = eval e1 env + eval e2 env
eval (Sub e1 e2) env = eval e1 env - eval e2 env
eval (Mult e1 e2) env = eval e1 env * eval e2 env
eval (EqualTo e1 e2) env | eval e1 env == eval e2 env = 1
                     | otherwise = 0 
eval (GreaterThan e1 e2) env | eval e1 env > eval e2 env = 1
             | otherwise = 0    
eval (LessThan e1 e2) env | eval e1 env < eval e2 env = 1
          | otherwise = 0
eval (NotEqual e1 e2) env | eval e1 env /= eval e2 env = 1
                      | otherwise = 0
eval (Mod e1) env =  mod eval e1 env  
  • 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-15T01:06:02+00:00Added an answer on June 15, 2026 at 1:06 am

    I assume that you are building an evaluator for AST, which represents a mathematical expression.

    Haskell function mod receives two arguments, but your AST receives only one argument, and function mod in your evaluator receives three arguments. Try to change the function eval and data Expr like this

    data Expr =
       | Mod Expr Expr
    
    eval :: Expr -> [(String, Integer)] -> Integer
    eval (Mod e1 e2) env = mod (eval e1 env) (eval e2 env)
    

    In the above code, function mod receives two arguments, eval e1 env and eval e2 env respectively.

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

Sidebar

Related Questions

Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I'm having trouble with the following code: def get_module(mod_path): mod_list = mod_path.split('.') mod =
I'm trying to install Redmine, and I am having trouble making Phusion Passenger work
I'm having trouble replicating the mod function in SQL sever. In excel, mod (-3,
I'm having trouble getting Apache/WSGI to use my VirtualEnv. I have added the following
I have been having some trouble getting the following to work: <IfModule mod_rewrite.c> DirectoryIndex
I'm having a trouble making a form work. As I see it, everything is
I am having a small trouble with mod rewrite. A friend of mine is
Having trouble with each function... Will try to explain by example... In my code,
Having trouble with an .htaccess file on WAMP. Works on the live server, but

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.