Seven More Languages in Seven Weeks (读书笔记):Idris

前端之家收集整理的这篇文章主要介绍了Seven More Languages in Seven Weeks (读书笔记):Idris前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Idris

  1. Day 1
    1. 基本上还是Haskell的语法?
    2. *functions>:t map
      Prelude.Functor.map: Functor f => (a -> b) -> (f a) -> f b
    3. map (\x => x * 0.5) (the (List Float) [3.14,2.78])
    4. 数据类型:idris/day1/data_types.idr
      data DumbNumber = Naught | One | Two | Three
      data MyList a = Blank | (::) a (MyList a)
    5. data Maybe a = Nothing | Just a
  2. Day 2:Dependent Types?(对value施加更多的约束)
    1. data Vect: Nat -> Type -> Type where //Vect is indexed by Nat and parameterized by Type
      Nil: Vect Z a
      (::): a -> Vect k a -> Vect (S k) a
      (++): Vect n a -> Vect m a -> Vect (n + m) a //新的类型声明
    2. data so: Bool -> Type where
      oh: so True
      so是依赖于Bool的类型(or 索引,indexed over Bool)
    3. (我感觉这种编译器的依赖类型约束推理其实给程序员增加了额外的复杂性,不见得有多高明)
  3. Day 3
    1. > idris proof.idr
      *proof>:e
    2. show plus x y等于plus y x(加法交换律):
      1. plus Zero y = plus y Zero
      2. If plus x y = plus y x,then plus (Suc x) y = plus y (Suc x)
    3. proof.idr:
      plusZero: (x: Natural) -> plus x Zero = x
      plusSuc: (x: Natural) -> (y: Natural) -> Suc (plus x y) = plus x (Suc y)
    4. Idris>:l proof.idr
      *proof>:m
      *proof>:p plusCommutes_0_y
      -Proof.plusCommutes_0_y> intros(称为 策略?)
      -Proof.plusCommutes_0_y> rewrite (plusZero y)
      -Proof.plusCommutes_0_y> trivial
      -Proof.plusCommutes_0_y> qed
    5. 总结:plusCommutes_0_y = proof {
      intros
      rewrite (plusZero y)
      trivial
      }
    6. 接下来,*proof>:p plusCommutes_Sx_y
      -Proof.plusCommutes_Sx_y> intros
      -Proof.plusCommutes_Sx_y> rewrite (plusSuc y x)
      定义hypothesis变量:plusCommutes (Suc x) y = let hypothesis = plusCommutes x y in?plusCommutes_Sx_y
      -Proof.plusCommutes_Sx_y> rewrite hypothesis
      -Proof.plusCommutes_Sx_y> trivial
      -Proof.plusCommutes_Sx_y> qed
  4. 辅助C++类型设计?

猜你在找的设计模式相关文章