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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:01:43+00:00 2026-06-12T00:01:43+00:00

I have this data type, which should represent a table: data R = R

  • 0

I have this data type, which should represent a table:

data R = R [Bool]  deriving Eq -- Row
data T = T [R]     deriving Eq -- Table

The problem is that it allows to have table of rows with different length, eg:

tab =T [R [True, False, True, True],
        R [False, False, True, False],
        R [False, False, False, True],
        R [False, False]]

Is it possible to modify the data definition of T to impose that all the R elements have the same length?

  • 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-12T00:01:44+00:00Added an answer on June 12, 2026 at 12:01 am

    You can do it with DataKinds. This may be overcomplicated, though:

    {-# LANGUAGE DataKinds, KindSignatures, GADTs #-}
    -- requires 7.4.1, I think
    
    data Nat = S Nat | Z
    
    infixr 0 :.
    data R (n :: Nat) where
      Nil :: R Z                     -- like []
      (:.) :: Bool -> R n -> R (S n) -- and (:)
    
    data T (n :: Nat) = T [R n]
    
    -- OK
    test1 = T [(True :. True :. Nil), (True :. False :. Nil)]
    
    -- will fail
    test2 = T [(True :. True :. Nil), (False :. Nil)]
    

    I’d rather recommend @MathematicalOrchids alternative approach using smart constructors.


    EDIT: What DataKinds do.

    The DataKinds extension lets the compiler automatically create a new kind other than * for each data type one writes, and new types living in this kind from the constructors.

    So Nat, besides being a simple ADT, also gives rise to a kind Nat , and type constructors Z :: Nat and S :: Nat -> Nat. This S is comparable to Maybe :: * -> * — it just doesn’t use the kind of all types, but your new kind Nat, inhabited only by the representations of the natural numbers.

    The point is, that now you also can define type constructors of mixed kinds. The classic example for this is Vec:

    data Vec (n :: Nat) (a :: *) where {-...-}
    

    which has kind Vec :: Nat -> * -> *. Similarly, T has kind T :: Nat -> *. This let’s you use it with a type-encoded constant lenght, and leads to a type error if one two rows of different lenght are put together.

    Although this looks extremely powerful, it is in fact restricted. To get the everything out of such representations, dependently typed languages should like Agda should be used.

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

Sidebar

Related Questions

I currently have this code which stores XML into an XML-type column called data,
I have this problem: The Vehicle type derives from the EntityObject type which has
I have this type of data: entity, account, month1, month2, ..., month12 abc, 2000.02,
Imagine I have a recursive algebraic data type like this (Haskell syntax): data Expr
I have a recursive data type like this: template<typename T> struct SomeType { std::map<T,
I have grabbed some XML data using this piece of jQuery: $.ajax({ type: POST,
I have a jQuery AJAX call with type:'GET' like this: $.ajax({type:'GET',url:'/createUser',data:userId=12345&userName=test, success:function(data){ alert('successful'); }
I need to achieve this: I have a sqlite table with this data slno
I have a Core Data model entity NoteObject that has a transformable type arrayOfTags
I have an application that allows different users to update some data that is

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.