We introduce Haskell. Why is it interesting. Where did it come from. What is it like. How to get started.
We show a GHCi session. We introduce simple recursive function and data. And we demo QuickCheck for testing properties of automatically generated data.
Software Engineering Thailand: Programming with ScalaBrian Topping
Meet-up, May 28, 2015, Launchpad, Bangkok. http://www.meetup.com/Software-Engineering-Thailand/events/222548484/.
Apologies for the rendering quality not matching the presentation, I did these with Apple Keynote and Slideshare does not support this format. I will try to edit them when there is more time.
Thanks to Bangkok LaunchPad (https://www.facebook.com/launchpadhq) for generously hosting this event!
Introduction to Scala Implicits, Pimp my library and TypeclassesJordi Pradel
An introduction to Scala implicits and the patterns they make possible, focusing on Pimp my library and type classes.
# Usage
- Clone the repo https://github.com/agile-jordi/scalabcn-implicits-2015
- When a slide "let's code!" is found, check out the commit corresponding to its first Step, and each consecutive step after that
- e.g. At slide 4 (let's code (Steps 1-3)), check out Step 1, read the code, then Step 2 and then Step 3. Then continue to slide 4.
Software Engineering Thailand: Programming with ScalaBrian Topping
Meet-up, May 28, 2015, Launchpad, Bangkok. http://www.meetup.com/Software-Engineering-Thailand/events/222548484/.
Apologies for the rendering quality not matching the presentation, I did these with Apple Keynote and Slideshare does not support this format. I will try to edit them when there is more time.
Thanks to Bangkok LaunchPad (https://www.facebook.com/launchpadhq) for generously hosting this event!
Introduction to Scala Implicits, Pimp my library and TypeclassesJordi Pradel
An introduction to Scala implicits and the patterns they make possible, focusing on Pimp my library and type classes.
# Usage
- Clone the repo https://github.com/agile-jordi/scalabcn-implicits-2015
- When a slide "let's code!" is found, check out the commit corresponding to its first Step, and each consecutive step after that
- e.g. At slide 4 (let's code (Steps 1-3)), check out Step 1, read the code, then Step 2 and then Step 3. Then continue to slide 4.
Break Free with Managed Functional Programming: An Introduction to F#IndyMobileNetDev
Dave Fancher presenting at the March Indy .NET Mobile Dev meetup:
Originally developed by Microsoft Research, Cambridge, F# is an open-source, functional-first language in the ML family. Despite its lofty position as a first-class Visual Studio language for the past two releases and its cross-platform availability it hasn't seen widespread adoption in the business world. These slides take you on an introductory tour of F#, exploring how its constructs and terse syntax can allow you to write more stable, maintainable code while keeping you focused on the problem rather than the plumbing.
Break Free with Managed Functional Programming: An Introduction to F#Dave Fancher
Originally developed by Microsoft Research, Cambridge, F# is an open-source, functional-first language in the ML family. Despite its lofty position as a first-class Visual Studio language for the past two releases and its cross-platform availability it hasn't seen widespread adoption in the business world. These slides take you on an introductory tour of F#, exploring how its constructs and terse syntax can allow you to write more stable, maintainable code while keeping you focused on the problem rather than the plumbing.
Elixir and Erlang share the same VM called BEAM. In this very practical demo, we discover some secrets of BEAM and OTP. This a refreshed version of an old presentations.
Natural Language Processing using JavaScript "Natural" Library. This deck covers Natural Language Understanding using JavaScript "Natural" library in detail
Outline of my experience introducing and championing the usage of Julia Language inside a medium sized Financial organization. Cover reason for using it, reason why I thought it was a good fit and some advice on how to improve other first experience
Automating boring and repetitive UbuCon Asia video and subtitle stuffsYoungbin Han
Whether it’s online or offline event, There’s always boring and repetitive jobs for event organizers and volunteers. Putting cover on session videos and making subtitle for videos are part of them. UbuCon Asia team, is no exception. But like you and other ordinary people, our organizers also have their own job and busy with that usually. As it’s first event we don’t even know if we can gather enough volunteers or gain sponsorship to hire some workers. So, We decided to use some automation tools like CI/CD, Speech to text, Translation API, Video cover rendering template and so on to automate these boring job as much as possible and reduce cost at the same time. In this session, I would like to share how we did this and what we’ve learned while trying to automate stuffs.
https://2021.ubucon.asia/sessions/automating_boring_and_repetitive_ubucon_asia_video_and_subtitle_stuffs
How I Learned to Stop Worrying and Love Legacy Code.....Mike Harris
Legacy Code. I never wrote it; everybody else did!
How many times have you waded through an ageing, decaying, tangled forrest of code and wished it would just die?
How many times have you heard someone say that what really needs to happen is a complete rewrite?
I have heard this many times, and, have uttered that fatal sentence myself.
But shouldn’t we love our legacy code?
Doesn’t it represent our investment and the hard work of ourselves and our predecessors?
Throwing it away is dangerous, because, before we do, we’ll need to work out exactly what it does, and we’ll need to tweeze out that critical business logic nestled in a deeply entangled knot of IF statements. It could take us years to do, and we’ll have to maintain two systems whilst we do it, inevitably adding new features to them both. Yes we get to reimplement using the latest, coolest programming language, instead of an old behemoth, but how long will our new cool language be around, and who will maintain that code, when it itself inevitably turns to legacy?
We can throw our arms in the air, complaining and grumbling about how we didn’t write the code, how we would never have written it the way it is, how those that wrote it were lesser programmers, possibly lesser humans themselves, but the code still remains, staring us in the face and hanging around for longer that we could possibly imagine. We can sort it out, we can improve it, we can make it testable, and we can learn to love our legacy code.
Build software like a bag of marbles, not a castle of LEGO®Hannes Lowette
If you have ever played with LEGO®, you will know that adding, removing or changing features of a completed castle isn’t as easy as it seems. You will have to deconstruct large parts to get to where you want to be, to build it all up again afterwards. Unfortunately, our software is often built the same way. Wouldn’t it be better if our software behaved like a bag of marbles? So you can just add, remove or replace them at will?
Most of us have taken different approaches to building software: a big monolith, a collection of services, a bus architecture, etc. But whatever your large scale architecture is, at the granular level (a single service or host), you will probably still end up with tightly couple code. Adding functionality means making changes to every layer, service or component involved. It gets even harder if you want to enable or disable features for certain deployments: you’ll need to wrap code in feature flags, write custom DB migration scripts, etc. There has to be a better way!
So what if you think of functionality as loose feature assemblies? We can construct our code in such a way that adding a feature is as simple as adding the assembly to your deployment, and removing it is done by just deleting the file. We would open the door for so many scenarios!
In this talk, I will explain how to tackle the following parts of your application to achieve this goal: WebAPI, Entity Framework, Onion Architecture, IoC and database migrations. And most of all, when you would want to do this. Because… ‘it depends’.
At least since the release of Java 8, functional programming has become mainstream in the Java community. Things like collection processing, lazy evaluation and concurrent programming are much easier to describe in a functional style than in the traditional procedural or object-oriented way.
Xtend is a Java dialect hosted at Eclipse. Designed to remove the syntactic noise, it offers a superior syntax and additional abstractions to provide the full power of functional programming to Java developers. As it compiles to Java 5 code, it will enable functional programming even for Android and GWT developers.
In this tutorial, you will learn the basic principles of functional programming and the Xtend idioms to write code the functional way: concise, easy to understand, and yet powerful. No prior knowledge of functional programming or Xtend required.
Break Free with Managed Functional Programming: An Introduction to F#IndyMobileNetDev
Dave Fancher presenting at the March Indy .NET Mobile Dev meetup:
Originally developed by Microsoft Research, Cambridge, F# is an open-source, functional-first language in the ML family. Despite its lofty position as a first-class Visual Studio language for the past two releases and its cross-platform availability it hasn't seen widespread adoption in the business world. These slides take you on an introductory tour of F#, exploring how its constructs and terse syntax can allow you to write more stable, maintainable code while keeping you focused on the problem rather than the plumbing.
Break Free with Managed Functional Programming: An Introduction to F#Dave Fancher
Originally developed by Microsoft Research, Cambridge, F# is an open-source, functional-first language in the ML family. Despite its lofty position as a first-class Visual Studio language for the past two releases and its cross-platform availability it hasn't seen widespread adoption in the business world. These slides take you on an introductory tour of F#, exploring how its constructs and terse syntax can allow you to write more stable, maintainable code while keeping you focused on the problem rather than the plumbing.
Elixir and Erlang share the same VM called BEAM. In this very practical demo, we discover some secrets of BEAM and OTP. This a refreshed version of an old presentations.
Natural Language Processing using JavaScript "Natural" Library. This deck covers Natural Language Understanding using JavaScript "Natural" library in detail
Outline of my experience introducing and championing the usage of Julia Language inside a medium sized Financial organization. Cover reason for using it, reason why I thought it was a good fit and some advice on how to improve other first experience
Automating boring and repetitive UbuCon Asia video and subtitle stuffsYoungbin Han
Whether it’s online or offline event, There’s always boring and repetitive jobs for event organizers and volunteers. Putting cover on session videos and making subtitle for videos are part of them. UbuCon Asia team, is no exception. But like you and other ordinary people, our organizers also have their own job and busy with that usually. As it’s first event we don’t even know if we can gather enough volunteers or gain sponsorship to hire some workers. So, We decided to use some automation tools like CI/CD, Speech to text, Translation API, Video cover rendering template and so on to automate these boring job as much as possible and reduce cost at the same time. In this session, I would like to share how we did this and what we’ve learned while trying to automate stuffs.
https://2021.ubucon.asia/sessions/automating_boring_and_repetitive_ubucon_asia_video_and_subtitle_stuffs
How I Learned to Stop Worrying and Love Legacy Code.....Mike Harris
Legacy Code. I never wrote it; everybody else did!
How many times have you waded through an ageing, decaying, tangled forrest of code and wished it would just die?
How many times have you heard someone say that what really needs to happen is a complete rewrite?
I have heard this many times, and, have uttered that fatal sentence myself.
But shouldn’t we love our legacy code?
Doesn’t it represent our investment and the hard work of ourselves and our predecessors?
Throwing it away is dangerous, because, before we do, we’ll need to work out exactly what it does, and we’ll need to tweeze out that critical business logic nestled in a deeply entangled knot of IF statements. It could take us years to do, and we’ll have to maintain two systems whilst we do it, inevitably adding new features to them both. Yes we get to reimplement using the latest, coolest programming language, instead of an old behemoth, but how long will our new cool language be around, and who will maintain that code, when it itself inevitably turns to legacy?
We can throw our arms in the air, complaining and grumbling about how we didn’t write the code, how we would never have written it the way it is, how those that wrote it were lesser programmers, possibly lesser humans themselves, but the code still remains, staring us in the face and hanging around for longer that we could possibly imagine. We can sort it out, we can improve it, we can make it testable, and we can learn to love our legacy code.
Build software like a bag of marbles, not a castle of LEGO®Hannes Lowette
If you have ever played with LEGO®, you will know that adding, removing or changing features of a completed castle isn’t as easy as it seems. You will have to deconstruct large parts to get to where you want to be, to build it all up again afterwards. Unfortunately, our software is often built the same way. Wouldn’t it be better if our software behaved like a bag of marbles? So you can just add, remove or replace them at will?
Most of us have taken different approaches to building software: a big monolith, a collection of services, a bus architecture, etc. But whatever your large scale architecture is, at the granular level (a single service or host), you will probably still end up with tightly couple code. Adding functionality means making changes to every layer, service or component involved. It gets even harder if you want to enable or disable features for certain deployments: you’ll need to wrap code in feature flags, write custom DB migration scripts, etc. There has to be a better way!
So what if you think of functionality as loose feature assemblies? We can construct our code in such a way that adding a feature is as simple as adding the assembly to your deployment, and removing it is done by just deleting the file. We would open the door for so many scenarios!
In this talk, I will explain how to tackle the following parts of your application to achieve this goal: WebAPI, Entity Framework, Onion Architecture, IoC and database migrations. And most of all, when you would want to do this. Because… ‘it depends’.
At least since the release of Java 8, functional programming has become mainstream in the Java community. Things like collection processing, lazy evaluation and concurrent programming are much easier to describe in a functional style than in the traditional procedural or object-oriented way.
Xtend is a Java dialect hosted at Eclipse. Designed to remove the syntactic noise, it offers a superior syntax and additional abstractions to provide the full power of functional programming to Java developers. As it compiles to Java 5 code, it will enable functional programming even for Android and GWT developers.
In this tutorial, you will learn the basic principles of functional programming and the Xtend idioms to write code the functional way: concise, easy to understand, and yet powerful. No prior knowledge of functional programming or Xtend required.
This presentation will introduce you to programming languages that support different programming paradigms and to give you the knowledge of basic concepts and techniques that will allow them to differentiate between various programming paradigms.
Keynote I did at JAX2013 with the topic basically being "the JVM is over - enter the Polyglot Runtime". It is about the work that Oracle and the community is doing to facilitate multiple languages (non Java) on the Java Virtual Machine. This is both relevant for dynamic languages as well as "non dynamic" ones.
What is Scala and how to functionally serve web content with Play! framework. It’s all about productively making correct and fast apps and to let you focus on the semantics. Success story of ditching PHP and going straight into functional web.
An overview of the programming techniques available and some of the ongoing research in the Haskell community around concurrent and parallel programming.
This was a short introduction to Scala programming language.
me and my colleague lectured these slides in Programming Language Design and Implementation course in K.N. Toosi University of Technology.
Little words of wisdom for the developer - Guillaume Laforge (Pivotal)jaxLondonConference
Presented at JAX London 2013 Community Night
Through some famous quotes and pictures that will make you think, Guillaume Laforge, Head of Groovy Development for SpringSource, will illustrate some simple principles that he has followed on the projects he’s worked on, and walk through the lessons he’s learned throughout the journey. Guillaume is the official Groovy Project Manager, and the spec lead of JSR-241, the JSR that standardizes the Groovy dynamic language.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
6. Why? Aesthetics
“We provided DARPA with a copy of our prototype
implemented in Haskell without explaining that it was
a program, and based on preconceptions from their
past experience, they had studied the program under
the assumption that it was a mixture of requirements
specification and top level design. They were
convinced it was incomplete because it did not address
issues such as data structure design and execution
order.”
— Paul Hudak
7. Why? Aesthetics
“Take Lisp: you know it's the most beautiful language
in the world. At least up until Haskell came along.”
— Larry Wall
23. Why? Pragmatics
“A programming language must be considered in the
context of its community, and Haskell has an
exemplary one. I have come to believe, however, that
this polite exterior conceals a deep and consuming
madness.”
— Avdi Grimm
39. Provide faster communication of new
ideas.
Stable foundation for real application
development.
Vehicle through which others would be
encouraged to use functional languages.
40. Who? When? Where?
Haskell Report
April 1st 1990
“You know, Haskell
actually never liked the
name Haskell.”
— Mary Curry
80. What? Monads
“Haskell is the world's finest
imperative programming language.”
— Simon Peyton-Jones
81. What? Monads
“Haskell is the only language I know with
first-class support for imperative programming.”
— SamB
82. What? Monads
“Haskell has no preferred imperative semantics, and
the monad just lets you swap out the semantics
according to your needs.”
— Jared Updike
100. What? Type Purity
No side effects
mean,
argument and return
types limit what
a function can do.
101. What? Type Purity
“Haskell is so strict about type safety that randomly
generated snippets of code that successfully type check
are likely to do something useful, even if you've no idea
what that useful thing is.”
— sigfpe
102. What? Type Purity
“Since when does "it compiles" equate to "it will run
(correctly)"? We're talking about C, after all, not
Haskell.”
— Sean Russell
128. "hello, world"
ghci> 6 * 9
42
ghci> [1, 2, 3]
[1,2,3] application is so important in Haskell that
“Function
ghci> it it using the quietest possible syntax:
we denote
[1,2,3]at all.”
nothing
ghci> reverse it
— Simon Peyton-Jones
129. “Function application is so important in Haskell that
we denote it using the quietest possible syntax:
nothing at all.”
— Simon Peyton-Jones
130. "hello, world"
ghci> 6 * 9
42
ghci> [1, 2, 3]
[1,2,3] application is so important in Haskell that
“Function
ghci> it it using the quietest possible syntax:
we denote
[1,2,3]at all.”
nothing
ghci> reverse it
— Simon Peyton-Jones
156. [22,23,⋯,99,100]
ghci> let divides = x y -> rem y x == 0
ghci> let divides x y = rem y x == 0
ghci> divides 3 12
True
ghci> 3 `divides` 12
157. [22,23,⋯,99,100]
ghci> let divides = x y -> rem y x == 0
ghci> let divides x y = rem y x == 0
ghci> divides 3 12
True
ghci> 3 `divides` 12
True
ghci>
158. [22,23,⋯,99,100]
ghci> let divides = x y -> rem y x == 0
ghci> let divides x y = rem y x == 0
ghci> divides 3 12
True
ghci> 3 `divides` 12
True
ghci> let divisors x = [d | d <- [1..x],
d `divides` x]
159. [22,23,⋯,99,100]
ghci> let divides = x y -> rem y x == 0
ghci> let divides x y = rem y x == 0
ghci> divides 3 12
True
ghci> 3 `divides` 12
True
ghci> let divisors x = [d | d <- [1..x],
d `divides` x]
ghci>
160. [22,23,⋯,99,100]
ghci> let divides = x y -> rem y x == 0
ghci> let divides x y = rem y x == 0
ghci> divides 3 12
True
ghci> 3 `divides` 12
True
ghci> let divisors x = [d | d <- [1..x],
d `divides` x]
ghci> divisors 100
161. [22,23,⋯,99,100]
ghci> let divides = x y -> rem y x == 0
ghci> let divides x y = rem y x == 0
ghci> divides 3 12
True
ghci> 3 `divides` 12
True
Fundamentals
ghci> let divisors x = [d | d <- [1..x],
d `divides` x]
ghci> divisors 100
[1,2,4,5,10,20,25,50,100]
ghci>
164. Variables
red = Red
-- Lower case for variable and upper case for
constructor.
nan = 0 / 0
-- Variables stand for values. They do not label
locations.
-- Don't need let because we aren't at GHCi.
-- Declarations go at top-level, not expressions.
(Like Java, unlike Ruby.)
170. Boolean Operators
True && x = x
False && _ = False
(||) True _ = True
(||) False x = x
-- Parenthesis let us use operators prefix.
171. Operator Precedence
infixr 3 &&
infixr 2 ||
-- Ten precedence levels: 0 binds least tightly, 9
(default) binds most tightly.
-- Three associativities: infixl (default), infixr,
infix (non-associative).
172. Types
“Types in Haskell express high-level design in the same
way that UML diagrams do in Object Oriented
languages.”
— Simon Peyton-Jones
173. Types
ghci> :l example
“Types in Haskell express high-level design in the same
way that UML diagrams do in Object Oriented
languages.”
— Simon Peyton-Jones
174. ghci> :l example
[1 of 1] Compiling Main
( example.hs, interpreted )
Ok, modules loaded: Main.
ghci>
175. ghci> :l example
[1 of 1] Compiling Main
( example.hs, interpreted )
Ok, modules loaded: Main.
ghci> :r
176. ghci> :l example
[1 of 1] Compiling Main
( example.hs, interpreted )
Ok, modules loaded: Main.
ghci> :r
Ok, modules loaded: Main.
ghci>
177. ghci> :l example
[1 of 1] Compiling Main
( example.hs, interpreted )
Ok, modules loaded: Main.
ghci> :r
Ok, modules loaded: Main.
ghci> :type red
178. ghci> :l example
[1 of 1] Compiling Main
( example.hs, interpreted )
Ok, modules loaded: Main.
ghci> :r
Ok, modules loaded: Main.
ghci> :type red
Red :: Color
ghci>
179. ghci> :l example
[1 of 1] Compiling Main
( example.hs, interpreted )
Ok, modules loaded: Main.
ghci> :r
Ok, modules loaded: Main.
ghci> :type red
Red :: Color
ghci> :t isRed
180. Types
ghci> :l example
[1 of 1] Compiling Main
( example.hs, interpreted )
Ok, :: Color loaded: Main.
red modules
ghci> Double
nan :: :r
Ok, modules loaded: Main.
ghci> Color -> Double
hue :: :type red
Red :: Color
otherwise :: Bool
ghci> :t isRed
isRed Bool -> Bool Bool
not :: :: Color ->
ghci> (||) :: Bool -> Bool -> Bool
(&&),
181. Types
red :: Color
nan :: Double
hue :: Color -> Double
otherwise :: Bool
not :: Bool -> Bool
(&&), (||) :: Bool -> Bool -> Bool
183. Recursive Data
data Color = Red | Green | Blue
| Mix Color Color
mix :: Color -> Color -> Color
mix = Mix
-- Mix is a type constructor function.
184. Recursive Data
yellow, cyan, magenta :: Color
yellow = Mix Red Green
Mix cyan magenta =
Mix (Mix Green Blue) (Mix Red Blue)
-- Constructor functions can be used for pattern
matching, but variables bind.
185. Recursive Functions
isRed :: Color -> Bool
isRed Red = True
isRed (Mix c c') = isRed c && isRed c'
isRed _ = False
192. h'
hue (Mix c c') = let
h = hue c
h' = hue c'
??? h
193. h' m
hue (Mix c c') = let
h = hue c
h' = hue c'
??? h
194. h' m
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
???
195. h' m
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
average x y = abs (x + y) / 2
???
196. h' m
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
average x y = abs (x + y) / 2
in m
197. h' m
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
average x y = abs (x + y) / 2
in ??!
198. m
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
average x y = abs (x + y) / 2
in ??!
h'
199. m
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
average x y = abs (x + y) / 2
in ??!
h' m'
200. m
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
m' = m + 180
average x y = abs (x + y) / 2
in ??!
h' m'
201. m d
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
m' = m + 180
average x y = abs (x + y) / 2
in ??!
h' m'
202. m d
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
m' = m + 180
d = distance h m
average x y = abs (x + y) / 2
in ??! h' m'
203. m d
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
m' = m + 180
d = distance h m
average x y = abs (x + y) / 2
distance x y = abs (x - y) h' m'
in ??!
204. m d
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
m' = m + 180
d = distance h m
average x y = abs (x + y) / 2
distance x y = abs (x - y) h' m'
in case compare d 90 of
LT -> m
EQ -> ??!
GT -> m'
205. m d
hue (Mix c c') = let
h = hue c
h' = hue c'
m = average h h' h
m' = m + 180
d = distance h m
average x y = abs (x + y) / 2
distance x y = abs (x - y) h' m'
in case compare d 90 of
LT -> m
EQ -> nan
GT -> m'
206. m d
hue (Mix c c') = r where
r = case compare d 90 of
LT -> m
EQ -> nan h
GT -> m'
h = hue c
h' = hue c'
m = average h h'
m' = m + 180 h' m'
d = distance h m
average x y = abs (x + y) / 2
distance x y = abs (x - y)
207. Testing
test-framework organize tests
HUnit what you’re used to
QuickCheck test properties with
automatically generated data
209. QuickCheck
prop_hue_bounds c = let h = hue c in
isNaN h || 0 <= h && h < 360
prop_hue_mix_reflexivity c = let h = hue c in
isNaN h || hue (Mix c c) == h
210. QuickCheck
prop_hue_bounds c = let h = hue c in
isNaN h || 0 <= h && h < 360
prop_hue_mix_reflexivity c = let h = hue c in
isNaN h || hue (Mix c c) == h
prop_hue_mix_commutativity c c' =
let h = hue (Mix c c') in
isNaN h || hue (Mix c' c) == h
211. QuickCheck
ghci> quickCheck prop_hue_mix_commutativi
ty
prop_hue_bounds c = let h = hue c in
isNaN h || 0 <= h && h < 360
prop_hue_mix_reflexivity c = let h = hue c in
isNaN h || hue (Mix c c) == h
prop_hue_mix_commutativity c c' =
let h = hue (Mix c c') in
isNaN h || hue (Mix c' c) == h
219. h'
hue (Mix c c') = r where
r = case compare d 90 of
LT -> m
EQ -> nan m m'
GT -> m'
h = hue c
h' = hue c'
m = average h h'
d h
m' = m + 180
d = distance h m
220. h'
hue (Mix c c') = r where
r = case compare d 90 of
LT -> m
EQ -> nan m m'
GT -> m'
h = hue c
h' = hue c'
m = average h h'
d h
m' = normalize (m + 180)
d = distance h m
221. h'
hue (Mix c c') = r where
r = case compare d 90 of
LT -> m
EQ -> nan m m'
GT -> m'
h = hue c
h' = hue c'
m = average h h'
d h
m' = normalize (m + 180)
d = distance h m
normalize h | h < 360 = h
| otherwise = h - 360
222. h'
hue (Mix c c') = r where
r = case compare d 90 of
LT -> m
EQ -> nan m m'
GT -> m'
h = hue c
h' = hue c'
m = average h h'
d h
m' = normalize (m + 180)
d = distance h m
normalize h | h < 360 = h
| otherwise = normalize (h - 360)
223. ghci> h'
hue (Mix c c') = r where
r = case compare d 90 of
LT -> m
EQ -> nan m m'
GT -> m'
h = hue c
h' = hue c'
m = average h h'
d h
m' = normalize (m + 180)
d = distance h m
normalize h | h < 360 = h
| otherwise = normalize (h - 360)
230. QuickCheck
prop_hue_mix_nothing c c' =
distance (hue c) (hue c') == 180 ==>
isNaN (hue (Mix c c'))
-- Can we easily find the complement of a color?
231. complement Red = ???
complement Green = ???
complement Blue = ???
complement (Mix c c') = ???
232. complement Red = cyan
complement Green = ???
complement Blue = ???
complement (Mix c c') = ???
233. complement Red = cyan
complement Green = magenta
complement Blue = ???
complement (Mix c c') = ???
234. complement Red = cyan
complement Green = magenta
complement Blue = yellow
complement (Mix c c') = ???
235. complement Red = cyan
complement Green = magenta
complement Blue = yellow
complement (Mix c c') = Mix ???
???
236. complement Red = cyan
complement Green = magenta
complement Blue = yellow
complement (Mix c c') = Mix (complement c )
(complement c' )
238. QuickCheck
prop_complement c = let h = hue c in
not (isNaN h) ==>
distance h (hue (complement c)) == 180
prop_hue_mix_complement c =
isNaN (hue (Mix c (complement c)))