Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Haskell



By Jackson Oliveira
       @cyber_jso
The First Version Is From Nineties
In The Beginning, It Was Just to Learn
But With The Principal Functional
       Programming Resources

 Curryng            Partial Processing


     FUNCTION COMPOSITION



Monads                      Lambda
So, What is Haskell Then?

• A Pure Functional Language.

• It’s Static Typed.

• It implement the immutable
concept.
Complex Things Looks Like Easy
It Uses a Lot of Recursion


                      There is
                      No Loops
How Can We Compile Haskell Code?

 • Glaskell Haskell Compiler

 • NHC98

 • Hugs (Intepreter)

 • LHC
Lets See Some code
Distributing an Application
module Main where

main = putStrLn "Hello Functional Society!“

In the command line:

> ghc -o hello main.hs
> ./hello
> Hello Functional Society!
List Handling
> 0:[1,2]       > map Char.toUpper "Hello World"
[0,1,2]         "HELLO WORLD“

                > zipWith „ (++) [“foo”, “bye”] [“bar”, “ bye”]
> 5:[1,2,3,4]   [“foo bar”, “bye bye”]
[5,1,2,3,4]
                > foldr (+) 0 [3,8,12,5]
                28

                > foldl (+) 0 [3,8,12,5]
                28
Recursion
module QuickSort where
                                  > quickSort [3, 1, 4]
quickSort [] = []                 > [1, 3, 4]

quickSort [x] = [x]

quickSort (x : xs) = (quickSort less)
                        ++ (x : equal)
                        ++ (quickSort more)
               where less = filter (< x) xs
                   equal = filter (== x) xs
                   more = filter (> x) xs
The Previous Recursion Wrote in C
void qsort(int a[], int lo, int hi)
{
  int h, l, p, t;
  if (lo < hi) {
    l = lo;
    h = hi;
    p = a[hi];
    do {
      while ((l < h) && (a[l] <= p))
          l = l+1;
      while ((h > l) && (a[h] >= p))
          h = h-1;
      if (l < h) {
          t = a[l];
          a[l] = a[h];
          a[h] = t;
      }
    } while (l < h);
    a[hi] = a[l];
    a[l] = p;
    qsort( a, lo, l-1 );
    qsort( a, l+1, hi );
  }
}
Let/in
letExample a b =
  let testValue = (+) a b
    in (((+) testValue 1),
       ((-) testValue 1))
Curryng

> max 5 4             > max 4
4                     > [function of max] 5
                      5


                      > f(x + y/2) = 2
                      >
                      5
Partial Processing

> add x y = x + y
> addOne = add 1
> addOne 2
3
Wild Cards

> caseExample x =      > [1 .. 10]
   case x of           [1,2,3,4,5,6,7,8,9,10]
    0 -> 1
    1 -> 5             > myFunction 3 = 3
    2 -> 2
    _ -> -1            > myFunction _ = 0
Advantages in Learn Haskell?

• Open your mind!

• Make your code cleaner

• It has a community supporting

• You have the control!
Ecosystem

• Web Frameworks!       • Persistence
                        Frameworks
• Test Frameworks.
                        • Web Servers
• Concurrency and
STM Frameworks
Disvantages

• It can Looks like complex in the
beginning.

• It isn’t performatic

• Doesn’t implement some bstractions
like other functional languages
Thank You!


        Haskell



        By Jackson Oliveira
               @cyber_jso

More Related Content

Haskell

  • 2. The First Version Is From Nineties
  • 3. In The Beginning, It Was Just to Learn
  • 4. But With The Principal Functional Programming Resources Curryng Partial Processing FUNCTION COMPOSITION Monads Lambda
  • 5. So, What is Haskell Then? • A Pure Functional Language. • It’s Static Typed. • It implement the immutable concept.
  • 7. It Uses a Lot of Recursion There is No Loops
  • 8. How Can We Compile Haskell Code? • Glaskell Haskell Compiler • NHC98 • Hugs (Intepreter) • LHC
  • 10. Distributing an Application module Main where main = putStrLn "Hello Functional Society!“ In the command line: > ghc -o hello main.hs > ./hello > Hello Functional Society!
  • 11. List Handling > 0:[1,2] > map Char.toUpper "Hello World" [0,1,2] "HELLO WORLD“ > zipWith „ (++) [“foo”, “bye”] [“bar”, “ bye”] > 5:[1,2,3,4] [“foo bar”, “bye bye”] [5,1,2,3,4] > foldr (+) 0 [3,8,12,5] 28 > foldl (+) 0 [3,8,12,5] 28
  • 12. Recursion module QuickSort where > quickSort [3, 1, 4] quickSort [] = [] > [1, 3, 4] quickSort [x] = [x] quickSort (x : xs) = (quickSort less) ++ (x : equal) ++ (quickSort more) where less = filter (< x) xs equal = filter (== x) xs more = filter (> x) xs
  • 13. The Previous Recursion Wrote in C void qsort(int a[], int lo, int hi) { int h, l, p, t; if (lo < hi) { l = lo; h = hi; p = a[hi]; do { while ((l < h) && (a[l] <= p)) l = l+1; while ((h > l) && (a[h] >= p)) h = h-1; if (l < h) { t = a[l]; a[l] = a[h]; a[h] = t; } } while (l < h); a[hi] = a[l]; a[l] = p; qsort( a, lo, l-1 ); qsort( a, l+1, hi ); } }
  • 14. Let/in letExample a b = let testValue = (+) a b in (((+) testValue 1), ((-) testValue 1))
  • 15. Curryng > max 5 4 > max 4 4 > [function of max] 5 5 > f(x + y/2) = 2 > 5
  • 16. Partial Processing > add x y = x + y > addOne = add 1 > addOne 2 3
  • 17. Wild Cards > caseExample x = > [1 .. 10] case x of [1,2,3,4,5,6,7,8,9,10] 0 -> 1 1 -> 5 > myFunction 3 = 3 2 -> 2 _ -> -1 > myFunction _ = 0
  • 18. Advantages in Learn Haskell? • Open your mind! • Make your code cleaner • It has a community supporting • You have the control!
  • 19. Ecosystem • Web Frameworks! • Persistence Frameworks • Test Frameworks. • Web Servers • Concurrency and STM Frameworks
  • 20. Disvantages • It can Looks like complex in the beginning. • It isn’t performatic • Doesn’t implement some bstractions like other functional languages
  • 21. Thank You! Haskell By Jackson Oliveira @cyber_jso