Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Haskell Introduction

Avatar for mina mina
July 14, 2018

Haskell Introduction

プログラミング言語のHaskellの紹介スライドです。

JOI2017夏季セミナーで作った資料な気がします。

Avatar for mina

mina

July 14, 2018
Tweet

More Decks by mina

Other Decks in Technology

Transcript

  1. 型宣言 Haskellは美しい data Color = Red | Blue | Yellow

    toJpn :: Color -> String toJpn Red = “aka” toJpn Blue = “ao” toJpn Yellow = “ki” main = print $ toJpn Red パターンマッチ 関数実行 & 出力 enum Color { Red, Blue, Yellow };
  2. 関数のいろいろ 関数名 引数1 引数2.......で呼び出し temp a b -> a `temp` b とも書ける (

    1 + ) , ( 5 * ) : 一引数関数 ( 1 + ) . ( 5 * ) : 関数合成 ( 5倍して1足す関数) f x y = print $ gcd x y f x = print . gcd x f = (print .) . gcd
  3. 二分探索木(木の定義) data Tree a = Leaf | Node (Tree a)

    a (Tree a) Leaf - 末端ノードの先にいる    実質虚無 末  Node - ただのノード 子を持ってる a ... ... 葉 葉
  4. 二分探索木(search関数) search::Ord a => Tree a -> a -> Bool

    search Leaf b = False search (Node tl a tr) b = if b < a then search tl b else if b > a then search tr b else True 型宣言 パターンマッチ