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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:43:04+00:00 2026-06-06T20:43:04+00:00

So, I finally found a task where I could make use of the new

  • 0

So, I finally found a task where I could make use of the new DataKinds extension (using ghc 7.4.1). Here’s the Vec I’m using:

data Nat = Z | S Nat deriving (Eq, Show)

data Vec :: Nat -> * -> * where
    Nil :: Vec Z a
    Cons :: a -> Vec n a -> Vec (S n) a

Now, for convenience I wanted to implement fromList. Basically no problem with simple recursion/fold — but I can’t figure out how to give it the correct type. For reference, this is the Agda version:

fromList : ∀ {a} {A : Set a} → (xs : List A) → Vec A (List.length xs)

My Haskell approach, using the syntax I saw here:

fromList :: (ls :: [a]) -> Vec (length ls) a
fromList [] = Nil 
fromList (x:xs) = Cons x (fromList xs)

This gives me a parse error on input 'a'. Is the syntax I found even correct, or have they changed it? I also added some more extensions which are in the code in the link, which didn’t help either (currently I have GADTs, DataKinds, KindSignatures, TypeOperators, TypeFamilies, UndecidableInstances).

My other suspicion was that I just can’t bind polymorphic types, but my test for this:

bla :: (n :: Nat) -> a -> Vec (S n) a
bla = undefined

failed, too, with Kind mis-match Expected kind 'ArgKind', but 'n' has kind 'Nat' (don’t really know what that means).

Could anyone help me with a working version of fromList and also clarify the other issues? Unfortunately, DataKinds isn’t documented very well yet and seems to assume that everybody using it has profound type theory knowledge.

  • 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-06T20:43:05+00:00Added an answer on June 6, 2026 at 8:43 pm

    Haskell, unlike Agda, does not have dependent types, so there is no way to do exactly what you want. Types cannot be parameterized by value, since Haskell enforces a phase distinction between runtime and compile time. The way DataKinds works conceptually is actually really simple: data types are promoted to kinds (types of types) and data constructors are promoted to types.

     fromList :: (ls :: [a]) -> Vec (length ls) a
    

    has a couple of problems: (ls :: [a]) does not really make sense (at least when you are only faking dependent types with promotion), and length is a type variable instead of a type function. What you want to say is

     fromList :: [a] -> Vec ??? a
    

    where ??? is the length of the list. The problem is that you have no way of getting the length of the list at compile time… so we might try

     fromList :: [a] -> Vec len a
    

    but this is wrong, since it says that fromList can return a list of any length. Instead what we want to say is

     fromList :: exists len. [a] -> Vec len a
    

    but Haskell does not support this. Instead

     data VecAnyLength a where
         VecAnyLength :: Vec len a -> VecAnyLength a 
    
     cons a (VecAnyLength v) = VecAnyLength (Cons a v)
    
     fromList :: [a] -> VecAnyLength a
     fromList []     = VecAnyLength Nil
     fromList (x:xs) = cons x (fromList xs)
    

    you can actually use a VecAnyLength by pattern matching, and thus getting a (locally) psuedo-dependently typed value.

    similarly,

    bla :: (n :: Nat) -> a -> Vec (S n) a
    

    does not work because Haskell functions can only take arguments of kind *. Instead you might try

    data HNat :: Nat -> * where
       Zero :: HNat Z
       Succ :: HNat n -> HNat (S n)
    
    bla :: HNat n -> a -> Ven (S n) a
    

    which is even definable

    bla Zero a     = Cons a Nil
    bla (Succ n) a = Cons a (bla n a)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found some manual here : http://support.microsoft.com/kb/316898/ru but can't make a step with :
I finally found some resources and a solution. I will share it here.
i finally found the perfect, simple jquery code for my new page: <script type=text/javascript>
Finally found out how to make DbgPrint to really print in Win Vista/7 with:
I have finally found the time to start learning KnockoutJS while building a new
I've finally found a client for my hosted software - the first time I've
I've finally found a way to debug classic asp code in visual studio 2008
I happened to something strange to me on CALayer.And finally found the CALayer's frame.size
I found out recently that JList (finally!) was generified in JDK7. Why JTree and
I am finally asking this question as I have never actually found an answer.

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.