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

PLT-A1 Programming Principles

PLT-A1 Programming Principles

Avatar for kanaya

kanaya

July 08, 2025
Tweet

More Decks by kanaya

Other Decks in Education

Transcript

  1. pineapple.cc ϓϩάϥϛϯάͷݪཧ w ஞ࣮࣍ߦ w ߦʢ1ZUIPOʣ w ηϛίϩϯɾΧϯϚʢ$ʣ w ৚݅෼ذ

    w JGจʢ1ZUIPO $ʣ w ࡾ߲ԋࢉࢠʢ$ʣ w ܁Γฦ͠ w GPSจʢ1ZUIPO $ʣ w ΠςϨʔλʢ1ZUIPO $ ʣ w Ϧετ಺แදهʢ1ZUIPOʣ w HPUPจʢ$ʣܧଓʢ4DIFNFʣ w ࠶ؼݺͼग़͠
  2. pineapple.cc y = f(x) z = g(y) z = (g

    ⋅ f)x y = fx z = gy z = (f ↣ g)x
  3. pineapple.cc f x = 2 * x g x =

    x + 1 x=10 z=(g.f)x (>->) f’ f’’ = f’’ . f’ z’=(f>->g)x Haskell
  4. pineapple.cc auto f(auto x) -> decltype (x) { return 2

    * x; } auto g(auto x) -> decltype (x) { return x + 1; } int x = 10; int z = g(f(x)); template <typename F1, typename F2> auto comp(F1 f1, F2 f2) { return [=](auto x){return f2(f1(x));}; } int z2 = comp([](auto x){return f(x);}, [](auto x){return g(x);})(10); C++
  5. pineapple.cc int main() { bool p = true; int x;

    if (p) { x = 1; } else { x = 0; } // do something return 0; } int main() { bool p = true; int x; x = p ? 1 : 0; // do something return 0; } C++
  6. pineapple.cc x = [0,1,2,…99] y = [2a ∣ a ∈

    x, even a] y′  = (map 2◊ ⋅ fi ltereven) x y′  ′  = ( fi ltereven ↣ map 2◊) x
  7. pineapple.cc x =[0,1..99] y =[2*a | a<-x, even a] y’

    =((map (2*)).(filter even))x y’’=((filter even)>->(map (2*))x Haskell
  8. pineapple.cc xn = 2n; 0 ≤ n < N s

    = N−1 ∑ n=0 xn x = [2n ∣ n ∈ [0,1,…, N − 1]] s = fold(+,0)x
  9. pineapple.cc ϕn = 0 where n = 0 1 where

    n = 1 ϕn−1 + ϕn−2 otherwise ϕ0 = 0 ϕ1 = 1 ϕn = ϕ(n − 1) + ϕ(n − 2)
  10. pineapple.cc phi 0 = 0 phi 1 = 1 phi

    n = phi (n-1) + phi (n-2) print (phi 10) Haskell