Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
pp:2026:l11 [2026/05/20 22:55]
ldaniel created
pp:2026:l11 [2026/05/20 23:32] (current)
ldaniel add link to types lab
Line 3: Line 3:
 ===== 11.0 Introduction ===== ===== 11.0 Introduction =====
  
-A powerful tool for understanding classes in Haskell is the '':​info <​class>''​ in the ghci command line:+'':​kind <​class>''​ and '':​info <​class>'' ​are two powerful tools for understanding classes in Haskell ​in the ghci command line:
  
 <code haskell> <code haskell>
->:info Eq+>:kind Eq
 type Eq :: * -> Constraint -- We'll return to this a bit later :-) type Eq :: * -> Constraint -- We'll return to this a bit later :-)
 +
 +>:info Eq
 class Eq a where -- Shows the blue-print of the class class Eq a where -- Shows the blue-print of the class
   (==) :: a -> a -> Bool   (==) :: a -> a -> Bool
Line 22: Line 24:
 If we look at Monad: If we look at Monad:
 <code haskell> <code haskell>
->:info Monad+>:kind Monad
 type Monad :: (* -> *) -> Constraint type Monad :: (* -> *) -> Constraint
 +
 +>:info Monad
 class Applicative m => Monad m where class Applicative m => Monad m where
   (>>=) :: m a -> (a -> m b) -> m b   (>>=) :: m a -> (a -> m b) -> m b
Line 38: Line 42:
 By looking at the Applicative:​ By looking at the Applicative:​
 <code haskell> <code haskell>
->:info Applicative+>:kind Applicative
 type Applicative :: (* -> *) -> Constraint type Applicative :: (* -> *) -> Constraint
 +
 +>:info Applicative
 class Functor f => Applicative f where class Functor f => Applicative f where
   pure :: a -> f a   pure :: a -> f a
Line 68: Line 74:
  
 ===== 11.1. Tasks ===== ===== 11.1. Tasks =====
 +[[https://​ocw.cs.pub.ro/​ppcarte/​doku.php?​id=pp:​2024:​l10 | Types in Haskell Lab]]
  
 For the following exercises: Define the data structure and instances for Eq, Show, Functor, Applicative (in 2 ways from scratch and based on Monad) and Monad (in 2 ways from scratch and based on Applicative) for the following: For the following exercises: Define the data structure and instances for Eq, Show, Functor, Applicative (in 2 ways from scratch and based on Monad) and Monad (in 2 ways from scratch and based on Applicative) for the following: