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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:25:09+00:00 2026-06-14T16:25:09+00:00

I create my own type parameters as follow: data Node a = Node a

  • 0

I create my own type parameters as follow:

data Node a = Node a

data Cost = Int | Float

data Edge Node Cost = Edge ((Node,Node),Cost)

data Graph Edge = Graph [Edge]

And get an error:

Unexpected type Node' where type variable expected
In the declaration of
Edge Node Cost’

How can I fix it?

  • 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-14T16:25:10+00:00Added an answer on June 14, 2026 at 4:25 pm

    Type Constructors vs Data Constructors

    You have to tag the types in a union type in haskell:

    data Cost = Int | Float
    

    should say

    data Cost = I Int | F Float
    

    Notice that this is because Int and Float are types. Example data would be I 5 or F 5.6. We need data constructors too. I and F are data constructors here. I :: Int -> Cost and F :: Float -> Cost. They’re functions that turn Ints or Floats into Costs. You can have a constructor that doesn’t take an argument, for example, as in your comment,

    data Bool = True | False
    

    Here True and False are constructors, not types. Example data would be just True or False. You do have to have constructors every time, which is why we need to tag the types Int and Float

    The definition

    data Node a = Node a
    

    is a bit confusing, because on the left hand side, Node is a sort of type function we call a type constructor, and has kind * -> *, but on the right hand side Node is a data constructor of type a -> Node a. Example data: Node "hello" of type Node String. This would be less confusing if we wrote

    data Node a = N a
    

    So Node is the type constructor and N is the data constructor. This gives sample data N "Hello" of type Node String. For this sort of definition, we haven’t made a lot of difference, so we tend to say

    newtype Node a = N a
    

    because the compiler can optimise it away in most cases, but we get type safety at the source code end.

    Type Constructors need types

    You also need

    data Edge a = Edge ((Node a,Node a),Cost)
    

    because Node is a type constructor (it has kind * -> *) so you have to always give it a type to work on. I’ve given it a so you can make your node out of anything.

    However, you don’t need the brackets, and a union of Int and Float is probably not as useful as allowing any cost type, by using lower case cost instead of the fixed type Cost

    data Edge a cost = Edge (Node a) (Node a) cost
    

    (If you want to make sure no-one ever makes an edge out of any cost that is non-numerical, you can say data Num cost => Edge a cost = Edge (Node a) (Node a) cost. In my view that’s a much better compromise between the awkwardness of tagging Int and Float and allowing arbitrary costs, but you don’t need it – you can quite happily add the restriction just exactly when you need it on a function that combines costs with +.)

    Your whole definitions would then be

    data Node a = Node a
    data Edge a cost = Edge (Node a) (Node a) cost
    data Graph a c = Graph [Edge a c]
    

    Again, you need to write Graph [Edge a c] because Edge takes two types, so has kind * -> * -> *.

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

Sidebar

Related Questions

I have my own type: CREATE TYPE MyType AS TABLE ( foo INT )
I create my own FrameworkElement and override VisualChildrenCount{get;} and GetVisualChild(int index) by returning my
I create own table type CREATE TYPE [dbo].[ObjectsList] AS TABLE( [Id] [int] NOT NULL,
I want to create my own custom collection type. I define my collection as:
I am planning to create my own custom Object Mapper for a type using
What I would like to do (in C++) is create a 'Parameter' data type
A while back I wanted to create my own data mapper that would be
I want to create own filetype to save objects in my app. Basically, I
I wish to create own events and dispatch them. I never done this before
In Wordpress it's possible to create own WP Querys for the loop. An example

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.