constraint-kinds

When (if ever) can type synonyms be partially applied?

走远了吗. 提交于 2019-12-08 15:15:19
问题 Apparently a bit absent-mindedly, I wrote something like the following: {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE TypeFamilies #-} class Foo f where type Bar f :: * retbar :: Bar f -> IO f type Baz f = (Foo f, Eq f) -- WithBar :: * -> (*->Constraint) -> * -> Constraint type WithBar b c f = (c f, Bar f ~ b) instance Foo () where type Bar () = () retbar = return naim :: WithBar () Baz u => IO u -- why can I do this? naim = retbar () main = naim :: IO () Only after successfully compiling, I

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

What is Constraint in kind signature

江枫思渺然 提交于 2019-12-01 03:55:37
If I inspect the kind of Maybe I get this: λ> :k Maybe Maybe :: * -> * Now, if I inspect the kind of Monad I get this: λ> :k Monad Monad :: (* -> *) -> Constraint What is Constraint there and why it is needed ? Why not just this * -> * ? Unlike Maybe , Monad is not a type ; it is a typeclass . The same goes for other typeclasses: Num :: * -> Constraint Functor :: (* -> *) -> Constraint Bifunctor :: (* -> * -> *) -> Constraint Where * represents concrete types (such as Bool or Int ), -> represent higher-kinded types (such as Maybe ), and Constraint represents the idea of a type constraint. This