1 / 26

Haskell

Haskell. Centro de Informática – UFPE. Roteiro. História Paradigma Utilização Sintaxe Implementação Exemplos Vantagens & Desvantagens. História. Desenvolvida em 1990 pelo FPAC Haskell 1.0 - 1.4 Haskell 98 Report Haskell-prime. Paradigma. Totalmente baseado em funções

yagil
Télécharger la présentation

Haskell

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Haskell Centro de Informática – UFPE

  2. Roteiro • História • Paradigma • Utilização • Sintaxe • Implementação • Exemplos • Vantagens & Desvantagens

  3. História • Desenvolvida em 1990 pelo FPAC • Haskell 1.0 - 1.4 • Haskell 98 Report • Haskell-prime

  4. Paradigma • Totalmente baseado em funções • Não existem atribuições (assignments) ! • Lazy Evaluation • High-order Functions

  5. Utilização • Jogos • Compiladores • IA (Problemas algébricos e lógica proposicional)

  6. Sintaxe • Trabalha-se somente com funções, seus parâmetros e seus retornos • É case-sensitive • Não possui comandos de repetição como While e For • Sem limites para identificadores

  7. Sintaxe • Tipos Básicos • Bool(Booleano) • Int(Inteiro limitado) • Integer(Inteiro ilimitado) • Float(Real) • Char(Caractere)

  8. Sintaxe( Tipos Básicos ) • Void • Tuplas • Listas • Funções

  9. Sintaxe • Módulos module Main where main = putStrLn “Hello, World!”

  10. Sintaxe • Funções multiplica x y = x*y

  11. Sintaxe • Listas ["Bob", "John"] "Bob" : "John" : []

  12. Sintaxe • :: (dois-pontos duplo) 5 :: Integer 'a‘ :: Char Inc :: Integer -> Integer [1,2,3] :: [Integer] ('b',4) :: (Char,Integer)

  13. Sintaxe • do main = do putStr "You are? " name <- getLine greet name Obs.: Utilização de layout (identação), substituindo os parênteses

  14. Sintaxe • Recursão (simulação de loops) printAll :: [String] -> IO () printAll [] = return () printAll (x:xs) = do putStrLn x printAll xs

  15. Sintaxe • Operador $ greet name = putStrLn $ greeting name

  16. Sintaxe • If then else greeting :: String -> String greeting name = if name = = "Haskell" then "Hey, whadda ya know? This is a Haskell program!" else "Hello, " ++ name ++ "!"

  17. Sintaxe • Outros • case • Sobrecarregamento (“Overloading”) • ect, etc...

  18. Implementação • Hugs • GHC • Nhc98 • HBC • Helium • Jhc • Yhc

  19. Implementação • Hugs • Interpretador • Escrito em C • Portável • Leve • Ideal para iniciantes

  20. Implementação • GHC • Interpretador e Compilador • Escrito em Haskell • Menos portável • Mais lento • Exige mais memória • Produz programas mais rápidos

  21. Exemplos module Main where main :: IO () main = do putStr “Qual é o seu nome? " nome <- getLine cumprimento nome cumprimento :: String -> IO () cumprimento nome = putStrLn $ cumprimentar nome

  22. Exemplos cumprimentar :: String -> String cumprimentar nome = if nome == "Haskell" then “Opa, eu te conheço? Este é um programa em Haskell!" else if nome == “Java" then “Boa linguagem" else “Olá, " ++ nome ++ "!"

  23. Vantagens • Fortemente Tipada e Estática • Avaliação Lazy • Polimorfismo Universal Paramétrico • Função (superior e parcial) • Ausência de variáveis globais e desvios incondicionais

  24. Desvantagens • Avaliação Lazy • Muita memória • Execução lenta

  25. Dúvidas

  26. Haskell Centro de Informática - UFPE

More Related