howtohaskell
TRANSCRIPT
-
8/6/2019 howtohaskell
1/33
How to Haskelligorgue.com
Saturday, August 6, 11
-
8/6/2019 howtohaskell
2/33
MePerson | Programmer | Politics Junky | Hipster Music
Saturday, August 6, 11
-
8/6/2019 howtohaskell
3/33
Programming LanguagesNERD
Saturday, August 6, 11
-
8/6/2019 howtohaskell
4/33
Bash | Boo | C | C# | C++ | Clojure | CoffeeScript |
Erlang | Gambas | Go | Haskell | Java | JavaScript |Lisp | Objective-C | PHP | Perl | Python | R | Ruby |
SQL | Scala | SuperCollider | Vala | Visual Basic
Saturday, August 6, 11
-
8/6/2019 howtohaskell
5/33
What is Haskell?
Saturday, August 6, 11
-
8/6/2019 howtohaskell
6/33
A standardized, general-purpose purely functionalprogramming language, with non-strict semanticsand strong static typing.
Saturday, August 6, 11
http://en.wikipedia.org/wiki/Type_system#Static_typinghttp://en.wikipedia.org/wiki/Type_system#Static_typinghttp://en.wikipedia.org/wiki/Strong_typinghttp://en.wikipedia.org/wiki/Strong_typinghttp://en.wikipedia.org/wiki/Non-strict_semanticshttp://en.wikipedia.org/wiki/Non-strict_semanticshttp://en.wikipedia.org/wiki/Programming_languagehttp://en.wikipedia.org/wiki/Programming_languagehttp://en.wikipedia.org/wiki/Purely_functionalhttp://en.wikipedia.org/wiki/Purely_functional -
8/6/2019 howtohaskell
7/33
Hello, World!
main = print "Hello, World!"
Saturday, August 6, 11
-
8/6/2019 howtohaskell
8/33
A Formal Hello
-- hello.hs: Saying "Hello, World!"module Mainwhere
main :: IO ()
main = putStrLn "Hello, World!"
Saturday, August 6, 11
-
8/6/2019 howtohaskell
9/33
Whats FunctionalProgramming?
Saturday, August 6, 11
-
8/6/2019 howtohaskell
10/33
Wait... Whats aFunction?
Saturday, August 6, 11
-
8/6/2019 howtohaskell
11/33
A function, in mathematics, associates one
quantity, the argumentof the function, also known asthe input, with another quantity, the value of thefunction, also known as the output.
Saturday, August 6, 11
http://en.wikipedia.org/wiki/Mathematicshttp://en.wikipedia.org/wiki/Mathematics -
8/6/2019 howtohaskell
12/33
Pure Functional Programming follows the same
definition as in mathematics. A function will outputthe same value if the same input is passed to it.
Saturday, August 6, 11
-
8/6/2019 howtohaskell
13/33
And a functional
programming languageis?
Saturday, August 6, 11
-
8/6/2019 howtohaskell
14/33
A programming language
where functions arefirst-class citizens
Saturday, August 6, 11
-
8/6/2019 howtohaskell
15/33
Cool Haskell Stuff
Saturday, August 6, 11
-
8/6/2019 howtohaskell
16/33
The only one purefunctional programming
languagehttp://www.youtube.com/watch?v=UuamC0T3hv8
Saturday, August 6, 11
http://www.youtube.com/watch?v=UuamC0T3hv8http://www.youtube.com/watch?v=UuamC0T3hv8 -
8/6/2019 howtohaskell
17/33
No Side-Effects! YAY!
Saturday, August 6, 11
-
8/6/2019 howtohaskell
18/33
A Side Effect
deffunction(y):
return y + x
x = 1print function(1) # => 2
x += 1print function(1) # => 3
Saturday, August 6, 11
-
8/6/2019 howtohaskell
19/33
Haskell Turn!
function y = y + x
x =1
function 1-- 2 (This wont be executed by the compiler)
x = x +1 -- SYNTAX ERROR!
function 1-- 3 (This will never happen)
Saturday, August 6, 11
-
8/6/2019 howtohaskell
20/33
Lazy Evaluation
Saturday, August 6, 11
-
8/6/2019 howtohaskell
21/33
Python vs Haskellprintrange(1, 10000000)[:3] # Python
print(take 3 [1..10000000]) -- Haskell
python range_of_10_mm.py 0.59s user 0.38s system 97% cpu 0.996 total
runhaskell range_of_10_mm.hs 0.21s user 0.04s system 90% cpu 0.270 total
print (take 3 [1..1000000000000000000000000000000]) -- Haskell
runhaskell range_of_many_mm.hs 0.21s user 0.04s system 92% cpu 0.271 total
Saturday, August 6, 11
-
8/6/2019 howtohaskell
22/33
Haskell is Dynamic Too!
Saturday, August 6, 11
-
8/6/2019 howtohaskell
23/33
string ="foobar"integer =10float =5.34
main =doputStrLn ("String: "++ string)putStrLn ("Integer: "++ show integer)
putStrLn ("Float: "++ show float)
Saturday, August 6, 11
-
8/6/2019 howtohaskell
24/33
But, Its Still StronglyTyped!
Saturday, August 6, 11
-
8/6/2019 howtohaskell
25/33
string :: Stringstring ="foobar"
integer :: Intinteger =10
float :: Floatfloat =5.34
main :: IO ()
main =doputStrLn ("String: "++ string)putStrLn ("Integer: "++ show integer)putStrLn ("Float: "++ show float)
Saturday, August 6, 11
-
8/6/2019 howtohaskell
26/33
My Recent ProblemImplementation of
in_groups_ofI solved it with Haskell... kinda
Saturday, August 6, 11
-
8/6/2019 howtohaskell
27/33
Problem
Given a list of n return a list of lists of x size. e.g.:
in_groups_of2 [1, 2, 3, 4, 5, 6]
[[1, 2], [3, 4], [5, 6]]
Saturday, August 6, 11
-
8/6/2019 howtohaskell
28/33
# File activesupport/lib/active_support/core_ext/array/grouping.rb, line
22
defin_groups_of(number, fill_with = nil) if fill_with == false
collection = self else
# size % number gives how many extra we have; # subtracting from number gives how many to add; # modulo number ensures we don't add group of just fill.
padding = (number - size % number) % numbercollection = dup.concat([fill_with] * padding)
end
if block_given?collection.each_slice(number) { |slice| yield(slice) }
elsereturning [] do |groups|collection.each_slice(number) { |group| groups
-
8/6/2019 howtohaskell
29/33
Haskell Turn!
inGroupsOf :: [a] -> Int -> [[a]]inGroupsOf [] _= []inGroupsOf xs n = let (ys, zs) = splitAt n xs
in ys : inGroupsOf zs n
Saturday, August 6, 11
-
8/6/2019 howtohaskell
30/33
Write Web Apps with
it!
http://snapframework.com/
Saturday, August 6, 11
http://snapframework.com/http://snapframework.com/ -
8/6/2019 howtohaskell
31/33
igorPage :: Application ()igorPage =do
message
-
8/6/2019 howtohaskell
32/33
Why Haskell?
Saturday, August 6, 11
-
8/6/2019 howtohaskell
33/33
BECAUSE HASKELL IS
FUN!!!Thanks!
http://igorgue.com/presentations/howtohaskell.pdf
http://igorgue.com/presentations/howtohaskell.pdfhttp://igorgue.com/presentations/howtohaskell.pdf