[Haskell-cafe] minor confusion over kinds....

Nicholls, Mark nicholls.mark at vimn.com
Wed May 6 12:01:39 UTC 2015


And what "*" means as opposed to other things e.g. an explicit name "Nat" or a kind variable "k"

> {-# LANGUAGE DataKinds #-}
> {-# LANGUAGE ExplicitForAll #-}
> {-# LANGUAGE FlexibleContexts #-}
> {-# LANGUAGE FlexibleInstances #-}
> {-# LANGUAGE GADTs #-}
> {-# LANGUAGE MultiParamTypeClasses #-}
> {-# LANGUAGE PolyKinds #-}
> {-# LANGUAGE StandaloneDeriving #-}
> {-# LANGUAGE TypeFamilies #-}
> {-# LANGUAGE TypeOperators #-}
> {-# LANGUAGE UndecidableInstances #-}

what I want is a typeclass with instances of type level Naturals

here's the class, the parameter is of kind (* -> *) i.e. a is some sort of wrapper that maps from types to values

> class Foo (a :: * -> *) where
>   type Bar a
>   bar :: a (Bar a)


lets ignore DataKinds define Zero and Succ as distinct types

uninhabited...but of kind "*" and "k -> *"

> data Z1
> data S1 nat

SNat1 :: * -> *

> data SNat1 a where
>   SZ1 :: SNat1 Z1
>   SS1 :: SNat1 a -> SNat1 (S1 a)

off we go...

> instance Foo SNat1 where
>   type Bar SNat1 = Z1
>   bar = SZ1


now lets do it the datakind route

> data Nat where
>   Z :: Nat
>   S :: Nat -> Nat

ahhh...SNat is of kind "Nat -> *"

> data SNat a where
>   SZ :: SNat 'Z
>   SS :: SNat a -> SNat ('S a)

so I cant make it an instance of the same type class

"The first argument of 'Foo' should have kind '* -> *',
      but 'SNat' has kind 'Nat -> *'
    In the instance declaration for 'Foo SNat'"


> --instance Foo SNat where
> --  type Bar SNat = 'Z
> --  bar = SZ

unless I redefine my class (which seems a bit silly)

> class Foo' (a :: k -> *) where
>   type Bar' a :: k
>   bar' :: a (Bar' a)

now it works.

> instance Foo' SNat where
>   type Bar' SNat = 'Z
>   bar' = SZ

clearly named kinds (?) are somehow distinct from unnames ones?
CONFIDENTIALITY NOTICE

This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited.

While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.

Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us.

MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe.  MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150506/1db21487/attachment.html>


More information about the Haskell-Cafe mailing list