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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:27:10+00:00 2026-05-19T14:27:10+00:00

I want to create several incompatible, but otherwise equal, datatypes. That is, I’d like

  • 0

I want to create several incompatible, but otherwise equal, datatypes. That is, I’d like to have a parameterized type Foo a, and functions such as

bar :: (Foo a) -> (Foo a) -> (Foo a) 

without actually caring about what a is. To clarify further, I’d like the type system to stop me from doing

x :: Foo Int
y :: Foo Char
bar x y

while I at the same time don’t really care about Int and Char (I only care that they’re not the same).

In my actual code I have a type for polynomials over a given ring. I don’t actually care what the indeterminates are, as long as the type system stops me from adding a polynomial in t with a polynomial in s. So far I’ve solved this by creating a typeclass Indeterminate, and parameterizing my polynomial type as

data (Ring a, Indeterminate b) => Polynomial a b

This approach feels perfectly natural for the Ring part because I do care about which particular ring a given polynomial is over. It feels very contrived for the Indeterminate part, as detailed below.

The above approach works fine, but feels contrived. Especially so this part:

class Indeterminate a where
    indeterminate :: a

data T = T

instance Indeterminate T where
    indeterminate = T

data S = S

instance Indeterminate S where
    indeterminate = S

(and so on for perhaps a few more indeterminates). It feels weird and wrong. Essentially I’m trying to demand that instances of Indeterminate be singletons (in this sense). The feeling of weirdness is one indicator that I might be attacking this wrongly. Another is the fact that I end up having to annotate a lot of my Polynomial a bs since the actual type b often cannot be inferred (that’s not strange, but is annoying nevertheless).

Any suggestions? Should I just keep on doing it like this, or am I missing something?

PS: Don’t feel offended if I don’t upvote or accept answers immediately. I’ll be unable to check back in for a few days.

  • 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-19T14:27:11+00:00Added an answer on May 19, 2026 at 2:27 pm

    First of all, I’m not sure this:

    data (Ring a, Indeterminate b) => Polynomial a b
    

    …is doing what you expect it to. Contexts on data definitions are not terribly useful–see the discussion here for some reasons why, most of which amount to them forcing you to add extra annotations without actually providing many additional type guarantees.

    Second, do you actually care about the “indeterminate” parameter other than to ensure that the types are kept distinct? A pretty standard way of doing that sort of thing is what’s called phantom types–essentially, parameters in the type constructor that aren’t used in the data constructor. You’ll never use or need a value of the phantom type, so functions can be as polymorphic as you want, e.g.:

    data Foo a b = Foo b
    
    foo :: Foo a b -> Foo a b
    foo (Foo x) = Foo x
    
    bar :: Foo a c -> Foo b c
    bar (Foo x) = Foo x
    
    baz :: Foo Int Int -> Foo Char Int -> Foo () Int
    baz (Foo x) (Foo y) = Foo $ x + y
    

    Obviously this does require annotations, but only in places where you’re deliberately adding restrictions. Otherwise, inference will work normally for the phantom type parameter.

    It seems to me that the above approach should be sufficient for what you’re doing here–the business with singleton types is mostly about bridging the gap between more complicated type-level stuff and regular value-level computations by creating type proxies for values. This could be useful for, say, marking vectors with types that indicate their basis, or marking numeric values with physical units–both cases where the annotation has more meaning than just “an indeterminate called X”.

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

Sidebar

Related Questions

I have a table of several hundred users and I want to create a
I have several custom uibuttons on my view. I want to create a toggle
If I have a human body 3d model, that I want to animate walking,
I'm struggling with this for several days now. I want to create a functions
I want to create a view that will display interesting stuff about the system
I want to create a really simple search form, basically a single field, that
Can I use template to create several instantiations of some function, different only in
I want to create a reusable component (a custom control) for the iPhone. It
I want to create a tab-enabled popup window in an AS3 Air project. Currently,
I'm pretty sure this can't be done in Oracle, but I'd love to be

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.