Type families with kind * -> *

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Type families with kind * -> *

Marco Túlio Gontijo e Silva-4
Hello,

I read the type families example at
http://haskell.org/haskellwiki/GHC/Indexed_types and I wanted to do
something similar to the Collects example, but using a type of kind * ->
*:

> class StateFunctor sf where
>   type SFMonad sf
>   type SFValue sf
>   sfmap :: (SFValue sf -> SFValue sf) -> sf -> SFMonad sf ()

I wrote the instance as:

> instance StateFunctor (ListStore a) where
>   type SFMonad (ListStore a) = IO
>   type SFValue (ListStore a) = a
>   sfmap function listStore
>     = listStoreGetSize listStore >>= listStoreSfmap function listStore

> listStoreSfmap :: (a -> a) -> ListStore a -> Int -> IO ()
> listStoreSfmap _function _listStore 0 = []
> listStoreSfmap function listStore size
>   = listStoreGetValue listStore index
>     >>= listStoreSetValue listStore index . function
>   >> listStoreSfmap function listStore index
>   where
>     index :: Int
>     index = pred size

I'm getting:

DistroCreator/GUI/List.hs:51:47:
    Kind error: `SFMonad' is applied to too many type arguments
    In the type `SFMonad sf ()'
    In the type `sf -> SFMonad sf ()'
    In the type `(SFValue sf -> SFValue sf) -> sf -> SFMonad sf ()'
Failed, modules loaded: none.

How can I use type families with types * -> *?

Greetings.

--
marcot
http://marcot.iaaeee.org/


Reply | Threaded
Open this post in threaded view
|

Type families with kind * -> *

Jason Dusek
class StateFunctor sf where
? type SFMonad sf :: * -> *
? type SFValue sf
? sfmap :: (SFValue sf -> SFValue sf) -> sf -> SFMonad sf ()
Reply | Threaded
Open this post in threaded view
|

Type families with kind * -> *

Daniel Fischer-4
In reply to this post by Marco Túlio Gontijo e Silva-4
Am Donnerstag 23 April 2009 19:15:05 schrieb Marco T?lio Gontijo e Silva:

> Hello,
>
> I read the type families example at
> http://haskell.org/haskellwiki/GHC/Indexed_types and I wanted to do
> something similar to the Collects example, but using a type of kind * ->
>
> *:
> > class StateFunctor sf where
> >   type SFMonad sf
> >   type SFValue sf
> >   sfmap :: (SFValue sf -> SFValue sf) -> sf -> SFMonad sf ()
>
> I wrote the instance as:
> > instance StateFunctor (ListStore a) where
> >   type SFMonad (ListStore a) = IO
> >   type SFValue (ListStore a) = a
> >   sfmap function listStore
> >     = listStoreGetSize listStore >>= listStoreSfmap function listStore
> >
> > listStoreSfmap :: (a -> a) -> ListStore a -> Int -> IO ()
> > listStoreSfmap _function _listStore 0 = []
> > listStoreSfmap function listStore size
> >   = listStoreGetValue listStore index
> >
> >     >>= listStoreSetValue listStore index . function
> >   >>
> >   >> listStoreSfmap function listStore index
> >
> >   where
> >     index :: Int
> >     index = pred size
>
> I'm getting:
>
> DistroCreator/GUI/List.hs:51:47:
>     Kind error: `SFMonad' is applied to too many type arguments
>     In the type `SFMonad sf ()'
>     In the type `sf -> SFMonad sf ()'
>     In the type `(SFValue sf -> SFValue sf) -> sf -> SFMonad sf ()'
> Failed, modules loaded: none.
>
> How can I use type families with types * -> *?

For example:
-----------------------------------
{-# LANGUAGE TypeFamilies, KindSignatures #-}
module TypeF where

data ListStore a = Dummy

listStoreGetSize = undefined
listStoreSfmap = undefined

class StateFunctor sf where
 ? type SFMonad sf :: (* -> *)
 ? type SFValue sf
 ? sfmap :: (SFValue sf -> SFValue sf) -> sf -> SFMonad sf ()

instance StateFunctor (ListStore a) where
 ? type SFMonad (ListStore a) = IO
 ? type SFValue (ListStore a) = a
 ? sfmap function listStore
 ? ? = listStoreGetSize listStore >>= listStoreSfmap function listStore

-------------------------------------
Prelude> :l TypeF
[1 of 1] Compiling TypeF            ( TypeF.hs, interpreted )
Ok, modules loaded: TypeF.


>
> Greetings.