SlideShare a Scribd company logo
10
     ruicc.rail@gmail.com
(Ruichi Kousuke)


@ruicc

http://d.hatena.ne.jp/ruicc
Haskell
10




     !!
Haskell Advent Calendar


                  Haskell Advent Calender
   2

 http://partake.in/events/eaea52c2-61ef-46d5-
 a855-3a2dde459e3a
Haskell Advent Calendar2011 2




      ruicc.rail@gmail.com
A   Haskell

B

A

B

A   ...
(OO)

(OO)          (Haskell)

  (Haskell)

                  10
(OO)   (Haskell)

(OO)   (Haskell)
Programming haskell chapter10
Programming haskell chapter10
(OO)




       =   +
(OO)




       =   +
(OO)   (Haskell)




(OO)   (Haskell)




                   Haskell
Programming haskell chapter10
Programming haskell chapter10
(Algebraic Data Type)


(Set)
Tuple (   )
or

Bool

  True or False
Programming haskell chapter10
data



data IntOrSome a = MkInt Int

                 | MkA   a
data



data IntOrSome a = MkInt Int

                 | MkA       a



          (OO            )
data      type


data IntOrSome a = MkInt Int

                 | MkA   a

type IntOrStr    = IntOrSome String
(            )




add :: Int -> Int -> Int

add a b   = a + b
Programming haskell chapter10
(OO)

class IntAndStr {
    private Int field1;
    private String field2;
    public IntAndStr (Int i, String s) {
      field1 = i; field2 = s;
    }
}
a = new IntAndStr(42, “aiueo”);
Haskell



data IntAndStr = MkIS Int String

let a = MkIS 42 “aiueo”
(OO)
Haskell


data Bool       = False    | True

data Maybe a    = Nothing | Just a

data Either a b = Left a   | Right b
(OO)
Haskell


data List a = Nil | Cons a (List a)

data Tree a = Leaf a
            | Node (Tree a) (Tree a)
(OO)   ..
FAQ



Q: Haskell     private

  A1: Python     dis

  A2: Javascript       (   )
Haskell    private(      )


     Haskell   private




 module
Haskell   private:




where

module
OOP




(OO)
:Haskell
Y
(OO)




       =   +
Programming haskell chapter10
Programming haskell chapter10
(       )

(   )
Haskell
Programming haskell chapter10
FAQ


C++   Python

  Y



  Y            Haskell
Haskell      (   )


C++,Python


  C++    :

  Python : C3
FAQ




    Scala   Trait

      scalaz              Trait
Haskell
class


built-in   Eq

class Eq a where

  (==), (/=) :: a -> a -> Bool
class




class Eq a where

  (==), (/=) :: a -> a -> Bool
class             instance
                   class          instance
                                             Eq
class Eq a where
  (==), (/=) :: a -> a -> Bool

                                             MyType
instance Eq MyType where
  x == y       = ...
  --   (==) :: MyType -> MyType -> Bool
class

                              Eq


class (Eq a) => Ord a where
  (<=) :: a -> a -> Bool      Ord
  ...
class


class (Eq a, Show a) => Num a where
  (+) :: a -> a -> a
  ...
                        Show          Eq




                               Num
Read
                        Show
           instance
                                       Typeable
                  Bounded      Ix
                       Enum            Data


                      Ord               Eq
instance


                              MyType
deriving

data        deriving

data MyType a b c = A a | B b | C c

   deriving (Eq, Ord, Show, Read)
                                         Read
                              Show
                        Ord                Eq



                                MyType
deriving                     FAQ




   URL: http://www.haskell.org/ghc/docs/7.2.2/html/
users_guide/deriving.html
Haskell



Haskell
instance Eq (Maybe Int)


    :: *
instance Monad Maybe
    :: * -> *
Monad, Functor, Applicative

More Related Content

Programming haskell chapter10

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n