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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:17:51+00:00 2026-05-29T22:17:51+00:00

I would like to do this: data Foo n = Foo $(tuple n Integer)

  • 0

I would like to do this:

data Foo n = Foo $(tuple n Integer)

and thus allow

x :: Foo 3
x = Foo (1, 2, 3)

y :: Foo 5
y = Foo (5, 4, 3, 2, 1)

Currently I have simply

data Foo = Foo [Integer]

which can be made to work, but throws away a lot of nice compile-time checking. I’ll be making a few different Foo data objects, and each will have a fixed number of foos throughout its lifespan, and it feels silly to not be able to check that in the type system.

Is this possible in haskell?

  • 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-29T22:17:52+00:00Added an answer on May 29, 2026 at 10:17 pm

    How about

    data IntAnd b = Int :. b
    infixr 5 :.
    

    So that way you can do

    data Foo n = Foo n
    
    x :: Foo (IntAnd (IntAnd Int))
    x = Foo (3 :. 4 :. 5)
    
    y :: Foo (IntAnd (IntAnd (IntAnd (IntAnd Int))))
    y = Foo (5 :. 4 :. 3 :. 2 :. 1)
    

    Or, if you want something a bit closer to your original syntax, try TypeFamilies:

    data One 
    data Succ a
    type Two = Succ One 
    type Three = Succ Two 
    type Four = Succ Three
    type Five = Succ Four
    
    class NTuple a where
      type IntTuple a
    
    instance NTuple One where
      type IntTuple One = Int 
    
    instance (NTuple a) => NTuple (Succ a) where
      type IntTuple (Succ a) = IntAnd (IntTuple a)
    
    x :: Foo (IntTuple Three)
    x = Foo (3 :. 4 :. 5)
    
    y :: Foo (IntTuple Five)
    y = Foo (5 :. 4 :. 3 :. 2 :. 1)
    

    Or with even more magic (TypeOperators, MultiParamTypeClasses, and FlexibleInstance, oh my!):

    data a :. b = a :. b
    infixr 5 :.
    
    class NTuple a b where
      type HomoTuple a b
    
    instance NTuple One b where
      type HomoTuple One b = b
    
    instance (NTuple a b) => NTuple (Succ a) b where
      type HomoTuple (Succ a) b = b :. HomoTuple a b
    
    x :: Foo (HomoTuple Three Int)
    x = Foo ( 3 :. 4 :. 5 )
    
    y :: Foo (HomoTuple Five Int)
    y = Foo ( 1 :. 2 :. 3 :. 4 :. 5 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have declaration like this: void Date::get_days_name(const Date& = this) which
I have a makefile with rules that look like this: data/foo-trunk.xml: svn log -v
I would like to do something like this: public class Foo { // Probably
Suppose we have a function like this one: foo (x, _, y) = (x,
I have three tables: page, attachment, page-attachment I have data like this: page ID
I have a class that looks roughly like this: template<std::size_t dim> class Foo {
I have a query that is basically like this: SELECT foo FROM bar where
I'm having data like this: uniqname1.foo.bar IN A 10.0.0.1 uniqname1.foo.bar IN TXT abcdefg uniqname2.foo.bar
I would like this to be the ultimate discussion on how to check if
I would like to do something like this: a rotating cube on a form.

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.