module Aula10 where import Aula8 import Aula9 import Data.List ((\\)) potencia :: Natural -> Natural -> Natural potencia n Zero = Suc Zero potencia n (Suc m) = produto (potencia n m) n -- exemplo bobo: receber inteiro e retornar string "Negativo", -- "Zero" ou "Positivo" sinal1 :: Integer -> String sinal1 x = if x < 0 then "Negativo" else if x == 0 then "Zero" else "Positivo" sinal2 :: Integer -> String sinal2 x | x < 0 = "Negativo" | x == 0 = "Zero" | otherwise = "Positivo" sinal3 :: Integer -> String sinal3 x = case x < 0 of True -> "Negativo" False -> case x == 0 of True -> "Zero" False -> "Positivo" ehZero :: Natural -> Bool ehZero n = case n of Zero -> True Suc _ -> False lista1 = [1, 2, 3] lista2 = 1 : 2 : 3 : [] -- data Lista a = Vazia | Cons a (Lista a) -- deriving Show data Lista a = Vazia | a :# Lista a deriving Show infixr 5 :# instance Functor Lista where fmap f Vazia = Vazia fmap f (cabeça :# cauda) = f cabeça :# fmap f cauda instance Eq a => Grupo [a] where op = (\\) -- "diferença de listas" inv = id neutro = [] x = 1 : 3 : 5 : y y = 7 : 8 : 9 : x z = 0 : 1 : zipWith (+) z (tail z) -- w = head $ tail w -- erro! head não retorna lista, -- mas tail precisa receber lista, então a recursão não funciona