SlideShare a Scribd company logo
1 of 3
Download to read offline
Resolução do teste de Programação Funcioal de 31/3/2014 sg nt
Crislânio Macêdo, 2014
--____________________________________________________________________________
Um pouco mais sobre dobras(folds 'r''l''r1''l1')
Primeiro vamos dar uma olhada na função foldl, também chamada de "left fold" (dobra esquerda).
Isto dobra a lista a partir do lado esquerdo
A função foldr dobra a lista a partir do lado direito.
As funções foldl1 e foldr1 funcionam da mesma forma que foldl e foldr, só que você não precisa
informar explicitamente qual o valor inicial.
Ele assume que o primeiro (ou último) elemento da lista é o valor inicial da dobra e então inicia a
dobra com ele.
foldr (+) 0 [1..10] valor inicial 0, 0+10+...1
foldl (+) 0 [1..10] valor inicial 0, 0+0+...10
foldr1(+) [1..10] valor inical 10,10+9...1
foldl1(+) [1..10] valor inical 1,1+2...10
Prelude> putStrLn $ foldr (x y -> concat ["(",x,"+",y,")"]) "0" (map show [1..13])
(1+(2+(3+(4+(5+(6+(7+(8+(9+(10+(11+(12+(13+0)))))))))))))
Prelude> putStrLn $ foldl (x y -> concat ["(",x,"+",y,")"]) "0" (map show [1..13])
(((((((((((((0+1)+2)+3)+4)+5)+6)+7)+8)+9)+10)+11)+12)+13)
Prelude> putStrLn $ foldr1 (x y -> concat ["(",x,"+",y,")"]) (map show [1..13])
(1+(2+(3+(4+(5+(6+(7+(8+(9+(10+(11+(12+13))))))))))))
Prelude> putStrLn $ foldl1 (x y -> concat ["(",x,"+",y,")"]) (map show [1..13])
((((((((((((1+2)+3)+4)+5)+6)+7)+8)+9)+10)+11)+12)+13)
Prelude> foldr (x y->x:'.':y) "" []:"ABC":[]
["","ABC"]
Prelude> foldr (x y->x:'.':y) "" "ABC":[]
["A.B.C."]
Prelude> foldr (x y->x:'.':y) "" "ABC"
"A.B.C."
Prelude> foldr (x y->x:'.':y) "" ['a']:"ABC":[]
["a.","ABC"]
--____________________________________________________________________________
--1° NIVEL 3
Prelude> length (filter (/='a') "banana")
3
Prelude> length (filter (/='n') "banana")
4
Prelude> length ([1,2]:[3,4]:[])
2
Prelude> length [1,3..7]
4
Prelude> length (drop 6 "abcdefg123")
4
Prelude> length ([1,2]:[3]:[])
2
Prelude> length [(x,y)| x<-"abc", y<-[0,1,2]]
9
Prelude> head [n | n<-[1..], n*n>15]
4
4
Prelude> head [n | n<-[1..], n*n>20]
5
Prelude> head([]++[1,2]++[3])
1
Prelude> [x | x<- "ab", n<-[1,2,3]]
"aaabbb"
Prelude> map (`div` 2) [1,2,3]
[0,1,1]
Prelude> (reverse [3,2])++ [4,5]
[2,3,4,5]
Prelude> reverse ([4,5]++[1,2,3])
[3,2,1,5,4]
--
Prelude> :t ([1,2,3], "banana")
([1,2,3], "banana") :: Num t => ([t], [Char])
Prelude> :t [(1,"banana"), (2,"maçã")]
[(1,"banana"), (2,"maçã")] :: Num t => [(t, [Char])]
--2° NIVEL 5
Prelude> foldr (-) (-2) [1,2,3,4]
-4
Prelude> foldr (-) (2) [1,2,3,4]
0
Prelude> foldl (-) (2) [1,2,3,4]
-8
Prelude> foldl (-) (-2) [1,2,3,4]
-12
--3° NIVEL 6
Prelude> foldr (+) 2 (map (+1) [1,2,3])
11
Prelude> foldl (+) 2 (map (+1) [1,2,3])
11
Prelude> foldr (-) 2 (map ((-)1) [1,2,2])
-2
Prelude> foldl (-) 2 (map ((-)1) [1,2,2])
4
Prelude> foldr(x y->x:'.':y) "" "PAULO"
"P.A.U.L.O."
Prelude> foldl(x y->x:'.':y) "" "ITALOS"
<interactive>:92:25:
Couldn't match expected type `[Char]' with actual type `Char'
Expected type: [[Char]]
Actual type: [Char]
In the third argument of `foldl', namely `"ITALOS"'
In the expression: foldl ( x y -> x : '.' : y) "" "ITALOS"
--4° NIVEL 7
Prelude> foldl (+) 0 (filter (>1) [sum(map ((-)1) [1,2,2])])
0
Prelude> sum(map (-1) [1,2,2])
<interactive>:96:10:
No instance for (Num (a1 -> a0))
arising from a use of syntactic negation
Possible fix: add an instance declaration for (Num (a1 -> a0))
In the first argument of `map', namely `(- 1)'
In the first argument of `sum', namely `(map (- 1) [1, 2, 2])'
In the expression: sum (map (- 1) [1, 2, 2])
Prelude> [map (>2) [1,2,3]] ++ ([]) ++ [[True]]
[[False,False,True],[True]]
Prelude> [map (>2) [1,6,6]] ++ ([]) ++ [[]]
[[False,True,True],[]]
Prelude> [map (>2) [-1, 2,4]] ++([])
[[False,False,True]]
--5° NIVEL MASTER
Prelude> foldr1 (-) [4,3,2]
3
Prelude> foldl1 (-) [-2,3,4]
-9

More Related Content

What's hot

What's hot (20)

CQL 实现
CQL 实现CQL 实现
CQL 实现
 
F# intro
F# introF# intro
F# intro
 
アプリカティブファンクターとHaskell 2014版
アプリカティブファンクターとHaskell 2014版アプリカティブファンクターとHaskell 2014版
アプリカティブファンクターとHaskell 2014版
 
Py3k
Py3kPy3k
Py3k
 
Clase de matlab
Clase de matlabClase de matlab
Clase de matlab
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)
 
(Fun)ctional go
(Fun)ctional go(Fun)ctional go
(Fun)ctional go
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
 
High Performance Mysql - Friday Tech Talks at Squareboat
High Performance Mysql - Friday Tech Talks at SquareboatHigh Performance Mysql - Friday Tech Talks at Squareboat
High Performance Mysql - Friday Tech Talks at Squareboat
 
Ch18 18
Ch18 18Ch18 18
Ch18 18
 
New text document
New text documentNew text document
New text document
 
Codigos
CodigosCodigos
Codigos
 
Cpl
CplCpl
Cpl
 
Vcs23
Vcs23Vcs23
Vcs23
 
5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment 5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment
 
StackArray stack3
StackArray stack3StackArray stack3
StackArray stack3
 
week-20x
week-20xweek-20x
week-20x
 
Cluto presentation
Cluto presentationCluto presentation
Cluto presentation
 

Similar to Resoluçãohaskell2

Session -5for students.pdf
Session -5for students.pdfSession -5for students.pdf
Session -5for students.pdfpriyanshusoni53
 
Lesson 01 A Warmup Problem
Lesson 01 A Warmup ProblemLesson 01 A Warmup Problem
Lesson 01 A Warmup ProblemMitchell Wand
 
funwithalgorithms.pptx
funwithalgorithms.pptxfunwithalgorithms.pptx
funwithalgorithms.pptxTess Ferrandez
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdfAshaWankar1
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilNova Patch
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202Mahmoud Samir Fayed
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptxRamiHarrathi1
 
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiufchapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiufWrushabhShirsat3
 
chapter7 Sorting.ppt
chapter7 Sorting.pptchapter7 Sorting.ppt
chapter7 Sorting.pptNielmagahod
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School ProgrammersSiva Arunachalam
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojureRoy Rutto
 
Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Ohgyun Ahn
 
Robotic Manipulator with Revolute and Prismatic Joints
Robotic Manipulator with Revolute and Prismatic JointsRobotic Manipulator with Revolute and Prismatic Joints
Robotic Manipulator with Revolute and Prismatic JointsTravis Heidrich
 
Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3guesta3202
 
PRESENTATION ON TUPLES.pptx
PRESENTATION ON TUPLES.pptxPRESENTATION ON TUPLES.pptx
PRESENTATION ON TUPLES.pptxrohan899711
 

Similar to Resoluçãohaskell2 (20)

Session -5for students.pdf
Session -5for students.pdfSession -5for students.pdf
Session -5for students.pdf
 
Lesson 01 A Warmup Problem
Lesson 01 A Warmup ProblemLesson 01 A Warmup Problem
Lesson 01 A Warmup Problem
 
funwithalgorithms.pptx
funwithalgorithms.pptxfunwithalgorithms.pptx
funwithalgorithms.pptx
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
 
6. list
6. list6. list
6. list
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx
 
Python overview
Python overviewPython overview
Python overview
 
chapter7.ppt
chapter7.pptchapter7.ppt
chapter7.ppt
 
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiufchapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
 
chapter7 Sorting.ppt
chapter7 Sorting.pptchapter7 Sorting.ppt
chapter7 Sorting.ppt
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojure
 
Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Python Usage (5-minute-summary)
Python Usage (5-minute-summary)
 
Robotic Manipulator with Revolute and Prismatic Joints
Robotic Manipulator with Revolute and Prismatic JointsRobotic Manipulator with Revolute and Prismatic Joints
Robotic Manipulator with Revolute and Prismatic Joints
 
Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 
PRESENTATION ON TUPLES.pptx
PRESENTATION ON TUPLES.pptxPRESENTATION ON TUPLES.pptx
PRESENTATION ON TUPLES.pptx
 

More from CRISLANIO MACEDO

Record Deduplication and Record Linkage
Record Deduplication and  Record LinkageRecord Deduplication and  Record Linkage
Record Deduplication and Record LinkageCRISLANIO MACEDO
 
Pitch selo sebrae - Hackathon 2019
Pitch selo sebrae - Hackathon 2019Pitch selo sebrae - Hackathon 2019
Pitch selo sebrae - Hackathon 2019CRISLANIO MACEDO
 
Search based gravitational algorithm
Search based gravitational algorithmSearch based gravitational algorithm
Search based gravitational algorithmCRISLANIO MACEDO
 
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...CRISLANIO MACEDO
 
Integración de métodos ágiles a una empresa de nivel 5 cmmi dev- un caso de e...
Integración de métodos ágiles a una empresa de nivel 5 cmmi dev- un caso de e...Integración de métodos ágiles a una empresa de nivel 5 cmmi dev- un caso de e...
Integración de métodos ágiles a una empresa de nivel 5 cmmi dev- un caso de e...CRISLANIO MACEDO
 
JGROUPS- A Toolkit for Reliable Multicast Communication
JGROUPS- A Toolkit for Reliable Multicast CommunicationJGROUPS- A Toolkit for Reliable Multicast Communication
JGROUPS- A Toolkit for Reliable Multicast CommunicationCRISLANIO MACEDO
 
Inteligência artificial algumas técnicas aplicadas em jogos
Inteligência artificial  algumas técnicas aplicadas em jogosInteligência artificial  algumas técnicas aplicadas em jogos
Inteligência artificial algumas técnicas aplicadas em jogosCRISLANIO MACEDO
 
Artigo ia traps, invariants, and dead-ends
Artigo ia   traps, invariants, and dead-endsArtigo ia   traps, invariants, and dead-ends
Artigo ia traps, invariants, and dead-endsCRISLANIO MACEDO
 
Análise dos dados abertos do governo federal
Análise dos dados abertos do governo federalAnálise dos dados abertos do governo federal
Análise dos dados abertos do governo federalCRISLANIO MACEDO
 
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...CRISLANIO MACEDO
 
Sistema de denúncia de desperdício de água - Etapa de Avaliação
Sistema de denúncia de desperdício de água - Etapa de AvaliaçãoSistema de denúncia de desperdício de água - Etapa de Avaliação
Sistema de denúncia de desperdício de água - Etapa de AvaliaçãoCRISLANIO MACEDO
 
Sistema de denúncia de desperdício de água - Etapa de Síntese
Sistema de denúncia de desperdício de água - Etapa de SínteseSistema de denúncia de desperdício de água - Etapa de Síntese
Sistema de denúncia de desperdício de água - Etapa de SínteseCRISLANIO MACEDO
 
Haskell aula7 libs_intro_arquivos
Haskell aula7 libs_intro_arquivosHaskell aula7 libs_intro_arquivos
Haskell aula7 libs_intro_arquivosCRISLANIO MACEDO
 
Haskell aula5 f.ordem-sup_modulos-cifra_cesar
Haskell aula5 f.ordem-sup_modulos-cifra_cesarHaskell aula5 f.ordem-sup_modulos-cifra_cesar
Haskell aula5 f.ordem-sup_modulos-cifra_cesarCRISLANIO MACEDO
 

More from CRISLANIO MACEDO (20)

Record Deduplication and Record Linkage
Record Deduplication and  Record LinkageRecord Deduplication and  Record Linkage
Record Deduplication and Record Linkage
 
Pitch selo sebrae - Hackathon 2019
Pitch selo sebrae - Hackathon 2019Pitch selo sebrae - Hackathon 2019
Pitch selo sebrae - Hackathon 2019
 
Pitch Medbloc
Pitch MedblocPitch Medbloc
Pitch Medbloc
 
Search based gravitational algorithm
Search based gravitational algorithmSearch based gravitational algorithm
Search based gravitational algorithm
 
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...
 
Integración de métodos ágiles a una empresa de nivel 5 cmmi dev- un caso de e...
Integración de métodos ágiles a una empresa de nivel 5 cmmi dev- un caso de e...Integración de métodos ágiles a una empresa de nivel 5 cmmi dev- un caso de e...
Integración de métodos ágiles a una empresa de nivel 5 cmmi dev- un caso de e...
 
JGROUPS- A Toolkit for Reliable Multicast Communication
JGROUPS- A Toolkit for Reliable Multicast CommunicationJGROUPS- A Toolkit for Reliable Multicast Communication
JGROUPS- A Toolkit for Reliable Multicast Communication
 
Inteligência artificial algumas técnicas aplicadas em jogos
Inteligência artificial  algumas técnicas aplicadas em jogosInteligência artificial  algumas técnicas aplicadas em jogos
Inteligência artificial algumas técnicas aplicadas em jogos
 
Artigo ia traps, invariants, and dead-ends
Artigo ia   traps, invariants, and dead-endsArtigo ia   traps, invariants, and dead-ends
Artigo ia traps, invariants, and dead-ends
 
Análise dos dados abertos do governo federal
Análise dos dados abertos do governo federalAnálise dos dados abertos do governo federal
Análise dos dados abertos do governo federal
 
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...
ANÁLISE ESTATÍSTICA DA RELAÇÃO ENTRE EVASÃO E AS RESPOSTAS DO QUESTIONÁRIO PA...
 
Sistema de denúncia de desperdício de água - Etapa de Avaliação
Sistema de denúncia de desperdício de água - Etapa de AvaliaçãoSistema de denúncia de desperdício de água - Etapa de Avaliação
Sistema de denúncia de desperdício de água - Etapa de Avaliação
 
Sistema de denúncia de desperdício de água - Etapa de Síntese
Sistema de denúncia de desperdício de água - Etapa de SínteseSistema de denúncia de desperdício de água - Etapa de Síntese
Sistema de denúncia de desperdício de água - Etapa de Síntese
 
Resolução lista2
Resolução lista2Resolução lista2
Resolução lista2
 
Haskell ufc quixadalista2
Haskell ufc quixadalista2Haskell ufc quixadalista2
Haskell ufc quixadalista2
 
Haskell ufc quixadalista1
Haskell ufc quixadalista1Haskell ufc quixadalista1
Haskell ufc quixadalista1
 
Haskell motivação
Haskell motivaçãoHaskell motivação
Haskell motivação
 
Haskell motivaçãoaula2
Haskell motivaçãoaula2Haskell motivaçãoaula2
Haskell motivaçãoaula2
 
Haskell aula7 libs_intro_arquivos
Haskell aula7 libs_intro_arquivosHaskell aula7 libs_intro_arquivos
Haskell aula7 libs_intro_arquivos
 
Haskell aula5 f.ordem-sup_modulos-cifra_cesar
Haskell aula5 f.ordem-sup_modulos-cifra_cesarHaskell aula5 f.ordem-sup_modulos-cifra_cesar
Haskell aula5 f.ordem-sup_modulos-cifra_cesar
 

Recently uploaded

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Recently uploaded (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

Resoluçãohaskell2

  • 1. Resolução do teste de Programação Funcioal de 31/3/2014 sg nt Crislânio Macêdo, 2014 --____________________________________________________________________________ Um pouco mais sobre dobras(folds 'r''l''r1''l1') Primeiro vamos dar uma olhada na função foldl, também chamada de "left fold" (dobra esquerda). Isto dobra a lista a partir do lado esquerdo A função foldr dobra a lista a partir do lado direito. As funções foldl1 e foldr1 funcionam da mesma forma que foldl e foldr, só que você não precisa informar explicitamente qual o valor inicial. Ele assume que o primeiro (ou último) elemento da lista é o valor inicial da dobra e então inicia a dobra com ele. foldr (+) 0 [1..10] valor inicial 0, 0+10+...1 foldl (+) 0 [1..10] valor inicial 0, 0+0+...10 foldr1(+) [1..10] valor inical 10,10+9...1 foldl1(+) [1..10] valor inical 1,1+2...10 Prelude> putStrLn $ foldr (x y -> concat ["(",x,"+",y,")"]) "0" (map show [1..13]) (1+(2+(3+(4+(5+(6+(7+(8+(9+(10+(11+(12+(13+0))))))))))))) Prelude> putStrLn $ foldl (x y -> concat ["(",x,"+",y,")"]) "0" (map show [1..13]) (((((((((((((0+1)+2)+3)+4)+5)+6)+7)+8)+9)+10)+11)+12)+13) Prelude> putStrLn $ foldr1 (x y -> concat ["(",x,"+",y,")"]) (map show [1..13]) (1+(2+(3+(4+(5+(6+(7+(8+(9+(10+(11+(12+13)))))))))))) Prelude> putStrLn $ foldl1 (x y -> concat ["(",x,"+",y,")"]) (map show [1..13]) ((((((((((((1+2)+3)+4)+5)+6)+7)+8)+9)+10)+11)+12)+13) Prelude> foldr (x y->x:'.':y) "" []:"ABC":[] ["","ABC"] Prelude> foldr (x y->x:'.':y) "" "ABC":[] ["A.B.C."] Prelude> foldr (x y->x:'.':y) "" "ABC" "A.B.C." Prelude> foldr (x y->x:'.':y) "" ['a']:"ABC":[] ["a.","ABC"] --____________________________________________________________________________ --1° NIVEL 3 Prelude> length (filter (/='a') "banana") 3 Prelude> length (filter (/='n') "banana") 4 Prelude> length ([1,2]:[3,4]:[]) 2
  • 2. Prelude> length [1,3..7] 4 Prelude> length (drop 6 "abcdefg123") 4 Prelude> length ([1,2]:[3]:[]) 2 Prelude> length [(x,y)| x<-"abc", y<-[0,1,2]] 9 Prelude> head [n | n<-[1..], n*n>15] 4 4 Prelude> head [n | n<-[1..], n*n>20] 5 Prelude> head([]++[1,2]++[3]) 1 Prelude> [x | x<- "ab", n<-[1,2,3]] "aaabbb" Prelude> map (`div` 2) [1,2,3] [0,1,1] Prelude> (reverse [3,2])++ [4,5] [2,3,4,5] Prelude> reverse ([4,5]++[1,2,3]) [3,2,1,5,4] -- Prelude> :t ([1,2,3], "banana") ([1,2,3], "banana") :: Num t => ([t], [Char]) Prelude> :t [(1,"banana"), (2,"maçã")] [(1,"banana"), (2,"maçã")] :: Num t => [(t, [Char])] --2° NIVEL 5 Prelude> foldr (-) (-2) [1,2,3,4] -4 Prelude> foldr (-) (2) [1,2,3,4] 0 Prelude> foldl (-) (2) [1,2,3,4] -8 Prelude> foldl (-) (-2) [1,2,3,4] -12 --3° NIVEL 6 Prelude> foldr (+) 2 (map (+1) [1,2,3]) 11 Prelude> foldl (+) 2 (map (+1) [1,2,3]) 11 Prelude> foldr (-) 2 (map ((-)1) [1,2,2]) -2 Prelude> foldl (-) 2 (map ((-)1) [1,2,2]) 4 Prelude> foldr(x y->x:'.':y) "" "PAULO" "P.A.U.L.O." Prelude> foldl(x y->x:'.':y) "" "ITALOS" <interactive>:92:25:
  • 3. Couldn't match expected type `[Char]' with actual type `Char' Expected type: [[Char]] Actual type: [Char] In the third argument of `foldl', namely `"ITALOS"' In the expression: foldl ( x y -> x : '.' : y) "" "ITALOS" --4° NIVEL 7 Prelude> foldl (+) 0 (filter (>1) [sum(map ((-)1) [1,2,2])]) 0 Prelude> sum(map (-1) [1,2,2]) <interactive>:96:10: No instance for (Num (a1 -> a0)) arising from a use of syntactic negation Possible fix: add an instance declaration for (Num (a1 -> a0)) In the first argument of `map', namely `(- 1)' In the first argument of `sum', namely `(map (- 1) [1, 2, 2])' In the expression: sum (map (- 1) [1, 2, 2]) Prelude> [map (>2) [1,2,3]] ++ ([]) ++ [[True]] [[False,False,True],[True]] Prelude> [map (>2) [1,6,6]] ++ ([]) ++ [[]] [[False,True,True],[]] Prelude> [map (>2) [-1, 2,4]] ++([]) [[False,False,True]] --5° NIVEL MASTER Prelude> foldr1 (-) [4,3,2] 3 Prelude> foldl1 (-) [-2,3,4] -9