Haskell/Kinds

< Haskell

Kinds for C++ users

 type MyType = Int
 type MyFuncType = Int -> Int
 myFunc :: Int -> Int
 typedef int MyType;
 typedef int (*MyFuncType)(int);
 int MyFunc(int a);


 data MyData t -- type constructor with kind * -> *
               = MyData t -- data constructor with type a -> MyData a
 *Main> :k MyData
 MyData :: * -> *
 *Main> :t MyData
 MyData :: a -> MyData a
 template <typename t> class MyData
 {
    t member;
 };


 data MyData t1 t2 = MyData t1 t2
 template <typename t1, typename t2> class MyData
 {
    t1 member1;
    t2 member2;
    MyData(t1 m1, t2 m2) : member1(m1), member2(m2) { }
 };


 data MyData tmpl = MyData (tmpl Int)
 template <template <typename t> class tmpl> class MyData
 {
    tmpl<int> member1;
    MyData(tmpl<int> m) : member1(m) { }
 };
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.