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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:10:08+00:00 2026-05-18T01:10:08+00:00

Apologies in advance if this question is a bit vague. It’s the result of

  • 0

Apologies in advance if this question is a bit vague. It’s the result of some weekend daydreaming.

With Haskell’s wonderful type system, it’s delightfully pleasing to express mathematical (especially algebraic) structure as typeclasses. I mean, just have a look at numeric-prelude! But taking advantage of such wonderful type structure in practice has always seemed difficult to me.

You have a nice, type-system way of expressing that v1 and v2 are elements of a vector space V and that w is a an element of a vector space W. The type system lets you write a program adding v1 and v2, but not v1 and w. Great! But in practice you might want to play with potentially hundreds of vector spaces, and you certainly don’t want to create types V1, V2, …, V100 and declare them instances of the vector space typeclass! Or maybe you read some data from the real world resulting in symbols a, b and c – you may want to express that the free vector space over these symbols really is a vector space!

So you’re stuck, right? In order to do many of the things you’d like to do with vector spaces in a scientific computing setting, you have to give up your typesystem by foregoing a vector space typeclass and having functions do run-time compatibility checks instead. Should you have to? Shouldn’t it be possible to use the fact that Haskell is purely functional to write a program that generates all the types you need and inserts them into the real program? Does such a technique exist? By all means do point out if I’m simply overlooking something basic here (I probably am) 🙂

Edit: Just now did I discover fundeps. I’ll have to think a bit about how they relate to my question (enlightening comments with regards to this are appreciated).

  • 1 1 Answer
  • 1 View
  • 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-18T01:10:08+00:00Added an answer on May 18, 2026 at 1:10 am

    Template Haskell allows this. The wiki page has some useful links; particularly Bulat’s tutorials.

    The top-level declaration syntax is the one you want. By typing:

    mkFoo = [d| data Foo = Foo Int |]
    

    you generate a Template Haskell splice (like a compile-time function) that will create a declaration for data Foo = Foo Int just by inserting the line $(mkFoo).

    While this small example isn’t too useful, you could provide an argument to mkFoo to control how many different declarations you want. Now a $(mkFoo 100) will produce 100 new data declarations for you. You can also use TH to generate type class instances. My adaptive-tuple package is a very small project that uses Template Haskell to do something similar.

    An alternative approach would be to use Derive, which will automatically derive type class instances. This might be simpler if you only need the instances.

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

Sidebar

Related Questions

This may be a bit of an abstract question, so apologies in advance. I
This is a very wide-ranging/vague question, but here goes. Apologies in advance. The app
All, Apologies in advance - this question might be too open-ended for SO. Anyway...
This, I'm sure is a pretty basic question about JavaScript, so apologies in advance.
First of all I apologize in advance for this question, a bit off the
Apologies in advance for the length of this question! I have a data structure
Apologies in advance because I'm really unsure how to ask this question so if
Apologies in advance for the rudimentary nature of this CSS question. I'm trying to
Apologies in advance if this question is badly worded! I have a MySQL table
(Apologies in advance if this question is short on details, I'll watch the comments

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.