Last active
October 11, 2020 00:33
-
-
Save romulogarofalo/9254e55eecd04ce248b7e08f67a2ac81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Aula4 where | |
-- polimorfismo parametrico | |
-- lembrar de falar de kind * -> * | |
data Coisa a = UmaCoisa a | DuasCoisas a a | ZeroCoisa | |
data Arvore a = Nulo | | |
Leaf a | | |
Branch a (Arvore a) (Arvore a) deriving Show | |
emOrdem :: Arvore a -> [a] | |
emOrdem (Branch x l r) = emOrdem l ++ [x] ++ emOrdem r | |
emOrdem (Leaf x) = x | |
emOrdem Nulo = [] | |
-- restricao de tipo em funcao | |
-- foo :: a -> String | |
-- foo x = "O valor de tipo a é: " ++ show x | |
-- foo :: Show a => a -> String | |
-- foo x = "O valor de tipo a é: " ++ show x | |
-- classe Eq | |
-- instance Eq a => Eq (Coisa a) where | |
-- (DuasCoisas x1 y1) == (DuasCoisas x2 y2) = x1 == y2 | |
-- (UmaCoisa x) == (UmaCoisa y) = x==y | |
-- Nada == Nada = True | |
-- _ == _ = False | |
-- classe Show | |
instance Show a => Show (Coisa a) where | |
show Nada = "Nadinha..." | |
show (UmaCoisa x) = "Coisa com o elemento " ++ show x | |
show (DuasCoisas x y) = "Coisa com os elementos " ++ (show x) ++ " e " ++ (show y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment