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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:08:59+00:00 2026-05-23T11:08:59+00:00

Hello Haskellers and Haskellettes, I’ve been fiddling around with Haskell for quite a while

  • 0

Hello Haskellers and Haskellettes,

I’ve been fiddling around with Haskell for quite a while but there is this concept of classes I cannot quite grasp. In the following example I have the datatype of ExprTree

data Val a = Num a | Var String deriving (Eq, Ord, Show)
data ExprTree = Leaf {lab::Label, val::(Val a)=> a}
          | Node {lab::Label, fun::Fun, lBranch::ExprTree, rBranch::ExprTree}
          deriving(Eq,Ord)

which leads to

Type constructor `Val' used as a class In the definition
of data constructor `Leaf' In the data type declaration for `ExprTree'

i also tried

data ExprTree' = Leaf {lab::Label, val::Val}
         ...

but randomly changing type signature – neither sounds efficent nor provides enlightenment.

now as far as i know Num a denotes something of class Num but is this is no instance of a datatype – and doesn’t let me compile.
So what do i have to do in order to make ExprTree well defined.

Thanks in advance for hints and ideas!


Edit:

1) Thanks for the fast answers!

2) I changed the val::(Val a)=>a to val::Val a

i had something similar in mind – but then the error: Not in scope type variable a occurs
do you have additional advice ??

  • 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-23T11:09:00+00:00Added an answer on May 23, 2026 at 11:09 am

    The correct type would be

    data Val a = Num a | Var String deriving (Eq, Ord, Show)
    data ExprTree a = Leaf {lab::Label, val :: Val a}
              | Node {lab::Label, fun::Fun, lBranch::ExprTree a, rBranch::ExprTree a}
              deriving(Eq,Ord)
    

    Since the type Val requires an additional type parameter, you need to provide one whenever you use it*. I used a type variable, just as in the initial definition; that requires the variable to also be named as a parameter to ExprTree. (The other possibilities would be to use a concrete type such as Int or Maybe String, etc., or to use an existential type; neither makes sense here.)

    What you actually used was a typeclass context (“class” is just shorthand for “typeclass”). Val is a type, not a typeclass, so it’s not legal there.

    * This isn’t quite true; you need a type of kind *. Kinds are the types of types: Int has kind *, Val a has kind *, Val has kind * -> *. That is, by itself Val is a type function which requires a parameter in order to become a full type.

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

Sidebar

Related Questions

Hello I have been having trouble with this for a while now. I have
Hello! I'm not even sure if this is possible, but hopefully it is in
Hello Haskellers and Haskellettes, when reading http://learnyouahaskell.com/ a friend of mine came up with
Hello everyone I am trying to resize an image of 700kb with imagecreatefromjpeg. This
Hello I wrote an application and while deploying shows error in line mCamera=Camera.open(); Where
Hello Guys I am trying to figure out why i am gettings this error
hello creating a custom object may be a widely published topic, but my lack
Hello StackOverflow, I'd like to know if there is way to trigger an event
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello and thank you in advance. I know this is total noob question, and

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.