data-kinds

DataKind Unions

坚强是说给别人听的谎言 提交于 2019-12-04 03:36:30
I'm not sure if it is the right terminology, but is it possible to declare function types that take in an 'union' of datakinds? For example, I know I can do the following: {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} ... data Shape' = Circle' | Square' | Triangle' data Shape :: Shape' -> * where Circle :: { radius :: Int} -> Shape Circle' Square :: { side :: Int} -> Shape Square' Triangle :: { a :: Int , b :: Int , c :: Int} -> Shape Triangle' test1 :: Shape Circle' -> Int test1 = undefined However, what if I want to take in a shape that is either a circle or a square? What if I also want

Can I provide the type-checker with proofs about inductive naturals in GHC 7.6?

纵然是瞬间 提交于 2019-12-03 15:15:21
问题 GHC 7.6.1 comes with new features for programming at the type level, including datatype promotion. Taking the example about type-level naturals and vectors from there, I'd like to be able to write functions on vectors that rely on basic laws of arithmetic. Unfortunately, even though the laws I want are typically easy to prove on inductive naturals by case analysis and induction, I'm doubt I can convince the type-checker of this. As a simple example, type-checking the naive reverse function

Haskell version of yin-yang puzzle : Kind incompatibility error

喜你入骨 提交于 2019-12-03 09:40:37
问题 I want to implement the yin-yang puzzle in Haskell. Here is my attempt (unsucceful): -- The data type in use is recursive, so we must have a newtype defined newtype Cl m = Cl { goOn :: MonadCont m => Cl m -> m (Cl m) } yinyang :: (MonadIO m, MonadCont m) => m (Cl m) yinyang = do yin <- (callCC $ \k -> return (Cl k)) >>= (\c -> liftIO (putStr "@") >> goOn c) yang <- (callCC $ \k -> return (Cl k)) >>= (\c -> liftIO (putStr "*") >> goOn c) goOn yin yang When look at the types, obviously callCC $

Can I provide the type-checker with proofs about inductive naturals in GHC 7.6?

…衆ロ難τιáo~ 提交于 2019-12-03 05:53:13
GHC 7.6.1 comes with new features for programming at the type level, including datatype promotion . Taking the example about type-level naturals and vectors from there, I'd like to be able to write functions on vectors that rely on basic laws of arithmetic. Unfortunately, even though the laws I want are typically easy to prove on inductive naturals by case analysis and induction, I'm doubt I can convince the type-checker of this. As a simple example, type-checking the naive reverse function below requires a proof that n + Su Ze ~ Su n . Is there any way I can supply that proof, or am I really

Type-level Map with DataKinds

萝らか妹 提交于 2019-12-01 11:44:17
I have a common pattern where I have a type-level list of kind [*] , and I would like to apply a type constructor of kind * -> * to each element in the list. For example, I would like to change the type '[Int, Double, Integer] to '[Maybe Int, Maybe Double, Maybe Integer] . Here's my attempt to implement a type-level map . {-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, TypeOperators, DataKinds, ScopedTypeVariables, GADTs #-} -- turns a type list '[b1, b2, b3] -- into the type list '[a b1, a b2, a b3] class TypeMap (a :: * -> *) (bs :: [*]) where type Map

List of any `DataKind` in GADT

落花浮王杯 提交于 2019-12-01 11:32:13
问题 Disclaimer GADTs & DataKinds are unexplored territory for me, so some of the limitations and capabilities of them are unknown to me. The Question So I'm writing an AST for a JavaScript code emitter, and I've identified one edge case between expressions and that is that they can either be a reference or not. So I've used GADTS and datakinds to type this aspect of JavaScript expression semantics. The ast looks something like this. Subset of the expression AST -- at the moment I'm just using a

Type-level Map with DataKinds

删除回忆录丶 提交于 2019-12-01 07:57:23
问题 I have a common pattern where I have a type-level list of kind [*] , and I would like to apply a type constructor of kind * -> * to each element in the list. For example, I would like to change the type '[Int, Double, Integer] to '[Maybe Int, Maybe Double, Maybe Integer] . Here's my attempt to implement a type-level map . {-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, TypeOperators, DataKinds, ScopedTypeVariables, GADTs #-} -- turns a type list '[b1, b2

Understanding this definition of HList

感情迁移 提交于 2019-11-29 11:08:19
I'm relatively new to Haskell, and I'm trying to understand one of the definitions of HList . data instance HList '[] = HNil newtype instance HList (x ': xs) = HCons1 (x, HList xs) pattern HCons x xs = HCons1 (x, xs) I have a couple specific questions: What is the '[] and (x ': xs) syntax I'm seeing? It almost looks like it's pattern matching on variadic type parameters, but I have never seen this syntax before, nor am I familiar with variadic type parameters in Haskell. I would guess this is part of GHC's Type Families , but I don't see anything about this on the linked page, and it's rather

What is the DataKinds extension of Haskell?

拟墨画扇 提交于 2019-11-28 17:44:11
I am trying to find an explanation of the DataKinds extension that will make sense to me having come from only having read Learn You a Haskell . Is there a standard source that will make sense to me with what little I've learned? Edit: For example the documentation says With -XDataKinds, GHC automatically promotes every suitable datatype to be a kind, and its (value) constructors to be type constructors. The following types and gives the example data Nat = Ze | Su Nat give rise to the following kinds and type constructors: Nat :: BOX Ze :: Nat Su :: Nat -> Nat I am not getting the point.

Understanding this definition of HList

随声附和 提交于 2019-11-28 04:42:59
问题 I'm relatively new to Haskell, and I'm trying to understand one of the definitions of HList. data instance HList '[] = HNil newtype instance HList (x ': xs) = HCons1 (x, HList xs) pattern HCons x xs = HCons1 (x, xs) I have a couple specific questions: What is the '[] and (x ': xs) syntax I'm seeing? It almost looks like it's pattern matching on variadic type parameters, but I have never seen this syntax before, nor am I familiar with variadic type parameters in Haskell. I would guess this is