type-kinds

What exactly is the kind “*” in Haskell?

我怕爱的太早我们不能终老 提交于 2020-05-20 11:14:09
问题 In Haskell, (value-level) expressions are classified into types , which can be notated with :: like so: 3 :: Int , "Hello" :: String , (+ 1) :: Num a => a -> a . Similarly, types are classified into kinds . In GHCi, you can inspect the kind of a type expression using the command :kind or :k : > :k Int Int :: * > :k Maybe Maybe :: * -> * > :k Either Either :: * -> * -> * > :k Num Num :: * -> Constraint > :k Monad Monad :: (* -> *) -> Constraint There are definitions floating around that * is

Unusual Kinds and Data Constructors

醉酒当歌 提交于 2020-01-02 05:39:12
问题 I don't know how I didn't notice this, but data constructors and function definitions alike can't use types with kinds other than * and it's variants * -> * etc., due to (->) 's kind signature, even under -XPolyKinds . Here is the code I have tried: {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} data Nat = S Nat | Z data Foo where Foo :: 'Z -> Foo -- Fails foo :: 'Z -> Int -- Fails foo _ = 1 The error I'm getting is the following: <interactive>:8:12: Expected a type, but ‘Z’ has

Is this a higher kinded type in Scala?

我的未来我决定 提交于 2019-12-22 05:28:14
问题 Having following definition type MyMap = Map[String, List[Map[Int, String]]] Can Map be defined as a higher kinded type ? 回答1: It should not. You can make an analogy with values and functions. You have basic values, which are not functions, such as 5 and "foo" . You have then simple functions, which takes simple values as arguments and return simple values, such as + or length . Higher order functions are functions which have other functions as parameters or result. For instance takeWhile ,

Kind vs Rank in type theory

跟風遠走 提交于 2019-12-20 12:36:11
问题 I'm having a hard time understanding Higher Kind vs Higher Rank types. Kind is pretty simple (thanks Haskell literature for that) and I used to think rank is like kind when talking about types but apparently not! I read the Wikipedia article to no avail. So can someone please explain what is a Rank? and what is meant by Higher Rank? Higher Rank Polymorphism? how that comes to Kinds (if any) ? Comparing Scala and Haskell would be awesome too. 回答1: The concept of rank is not really related to

What does * (star) or other kinds mean in an instance list of haddock

你。 提交于 2019-12-19 18:22:09
问题 Browsing the haddocks of various packages I often come along instance documentations that look like this (Control.Category): Category k (Coercion k) Category * (->) or this (Control.Monad.Trans.Identity): MonadTrans (IdentityT *) What exactly here does the kind signature mean? It doesn't show up in the source, but I have already noticed that it seems to occur in modules that use the PolyKinds extension. I suspect it is probably like a TypeApplication but with a kind. So that e.g. the last

Unusual Kinds and Data Constructors

感情迁移 提交于 2019-12-05 18:19:14
I don't know how I didn't notice this, but data constructors and function definitions alike can't use types with kinds other than * and it's variants * -> * etc., due to (->) 's kind signature, even under -XPolyKinds . Here is the code I have tried: {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} data Nat = S Nat | Z data Foo where Foo :: 'Z -> Foo -- Fails foo :: 'Z -> Int -- Fails foo _ = 1 The error I'm getting is the following: <interactive>:8:12: Expected a type, but ‘Z’ has kind ‘Nat’ In the type signature for ‘foo’: foo :: 'Z -> Int Why shouldn't we allow pattern matching

Is it possible to get the Kind of a Type Constructor in Haskell?

主宰稳场 提交于 2019-12-05 14:38:14
问题 I am working with Data.Typeable and in particular I want to be able to generate correct types of a particular kind (say * ). The problem that I'm running into is that TypeRep allows us to do the following (working with the version in GHC 7.8): let maybeType = typeRep (Proxy :: Proxy Maybe) let maybeCon = fst (splitTyConApp maybeType) let badType = mkTyConApp maybeCon [maybeType] Here badType is in a sense the representation of the type Maybe Maybe, which is not a valid type of any Kind: > :k

Is this a higher kinded type in Scala?

橙三吉。 提交于 2019-12-05 05:58:34
Having following definition type MyMap = Map[String, List[Map[Int, String]]] Can Map be defined as a higher kinded type ? It should not. You can make an analogy with values and functions. You have basic values, which are not functions, such as 5 and "foo" . You have then simple functions, which takes simple values as arguments and return simple values, such as + or length . Higher order functions are functions which have other functions as parameters or result. For instance takeWhile , map , or foldLeft are higher order functions. If you consider types, there are simple types, which are the

ConstraintKinds explained on a super simple example

♀尐吖头ヾ 提交于 2019-12-04 07:50:08
问题 What is a Constraint kind? Why would someone use it (in practice)? What is it good for? Could you give a simple code example to illustrate the answers to the previous two questions? Why is it used in this code for example? 回答1: Well, I'll mention two practical things it allows you to do: Parametrize a type by a type class constraint Write type classes that allow their instances to specify constraints that they need. Maybe it's best to illustrate this with an example. One of the classic

Is polykinded type application injective?

試著忘記壹切 提交于 2019-12-04 01:18:48
问题 Is polykinded type application injective? When we enable PolyKinds, do we know that f a ~ g b implies f ~ g and a ~ b ? Motivation When trying to answer another question, I reduced the problem to the point that I received the following error only with PolyKinds enabled. Could not deduce (c1 ~ c) from the context ((a, c z) ~ (c1 a1, c1 b)) If polykinded type application were injective, we could deduce c1 ~ c as follows. (a, c z) ~ (c1 a1, c1 b) (a,) (c z) ~ (c1 a1,) (c1 b) {- switch to prefix