epogrebnyak / haskell-intro

Seven classes on Haskell and a follow-up reading list
http://tinyurl.com/haskell-intro
53 stars 6 forks source link

`-> Constraint` in kind signature is a typeclass #11

Open epogrebnyak opened 4 years ago

epogrebnyak commented 4 years ago

https://kseo.github.io/posts/2017-01-13-constraint-kinds.html says

Classes such as Functor or Monad are of kind (* -> *) -> Constraint. They form a class constraint when applied to type constructors of kind * -> *.

See https://www.haskell.org/tutorial/classes.html

Also String is kind *, similar to Maybe Int.

In OOP class is also type. In Haskell class in a grouping of types that have common methods. Eq groups type of signature (kind) *. Monad groups types of kind * -> *

Monad is constrained to work on kinds -> by its signature.

types are build-in or created by data, newtype or type.

class Applicative m => Monad (m :: * -> *) where -- m will need  * -> *
  (>>=) :: m a -> (a -> m b) -> m b
  (>>) :: m a -> m b -> m b
  return :: a -> m a
  fail :: String -> m a

See strange prelude https://github.com/copton/haskell-examples/blob/master/typeclassopedia/bottomup.hs

Try kinds of typeclasses from https://en.wikibooks.org/wiki/Haskell/Classes_and_types#Type_constraints

Reason about :k (->)