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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:45:47+00:00 2026-05-11T11:45:47+00:00

Based on some advice I found on StackOverflow, I’m digging into Haskell. I was

  • 0

Based on some advice I found on StackOverflow, I’m digging into Haskell. I was pleased to see that Haskell’s parameterized types behave very much like C# generics. Both languages advise a single letter for the type parameter (usually), and both languages seem to follow a similiar process for substituting an actual type for the type parameter. I grokked the concept pretty quickly because of that.

Which leads to this: what are some ways in which Haskell’s parameterized types differ from C# generic types? I know from learning Ruby that you can get into big trouble thinking that a concept you’re familiar with from one language is the same in another language you’re new to. Usually, the trouble is worse when the features actually are very similar … because they’re usually not 100% the same. So what are some of the ‘gotchas’ I might get bitten by if I assume I understand parameterized types based on my knowledge of C# generics?

Thanks.

  • 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. 2026-05-11T11:45:48+00:00Added an answer on May 11, 2026 at 11:45 am

    Here’s one difference to keep in mind:

    C# has subtyping, but Haskell does not, which means, for one thing, that you know more things by simply looking at a Haskell type.

    id :: a -> a 

    This Haskell function takes a value of a type and returns that same value of that same type. If you give it a Bool, it will return a Bool. Give it a Int, it will return a Int. Give it a Person, it will return a Person.

    In C#, you can’t be so sure. This is that ‘function’ in C#:

    public T Id<T>(T x); 

    Now, because of subtyping you could call it like so:

    var pers = Id<Person>(new Student()); 

    While pers is of type Person, the argument to the Id function is not. In fact pers might have a more specific type than just Person. Person could even be an abstract type, guaranteeing that pers will have a more specific type.

    As you can see, even with a function as simple as id the .NET type system already allows for a lot more than the stricter type system from Haskell. While that might be useful to do some programming work, it also makes it harder to reason about a program by just looking a the types of things (which is a joy to do in Haskell).


    And a second thing, there is ad hoc polymorphism (aka overloading) in Haskell, via a mechanism known as ‘type classes’.

    equals :: Eq a => a -> a -> Bool 

    This function checks if two values are equal. But not just any two values, just the values that have instances for the Eq class. This is sort of like constraints on type parameters in C#:

    public bool Equals<T>(T x, T y) where T : IComparable 

    There is a difference, however. For one thing, the subtyping: you could instantiate it with Person and call it with Student and Teacher.

    But there is also a difference in what this compiles to. The C# code compiles to almost exactly what its type says. The type checker makes sure the arguments implement the proper interface, and than you’re good.

    Whereas the Haskell code complies to something like this:

    equals :: EqDict -> a -> a -> Bool 

    The function gets an extra argument, a dictionary of all the functions it needs to do the Eq things. Here’s how you could use this function, and what it compiles to:

    b1 = equals 2 4          --> b1 = equals intEqFunctions 2 4 b2 = equals True False   --> b2 = equals boolEqFunctions True False 

    This also shows what makes subtyping such a pain, imagine if this where possible.

    b3 = equals someStudent someTeacher      --> b3 = equals personEqFunctions someStudent someTeacher 

    How is the personEqFunctions dictionary supposed to figure out if a Student is equal to a Teacher? They don’t even have the same fields.

    In short, while Haskell type constraints at first sight might look like .NET type constraints, they are implemented completely differently and compile to two really different things.

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

Sidebar

Ask A Question

Stats

  • Questions 115k
  • Answers 115k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Gah, my eyes! Try doing this in code behind instead:… May 11, 2026 at 10:29 pm
  • Editorial Team
    Editorial Team added an answer As you've written 'A' and 'B', you don't actually need… May 11, 2026 at 10:29 pm
  • Editorial Team
    Editorial Team added an answer http://schlueters.de/colorgcc.html May 11, 2026 at 10:29 pm

Related Questions

Based on some advice I found on StackOverflow, I'm digging into Haskell. I was
I need to build a simple webservice to get data in and out of
I was digging around in MSDN and found this article which had one interesting
I'm using Delphi 2007 Pro. I have a runtime package that includes a number
We're looking for some advice on our StarTeam configuration. We have a project that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.