加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 02:16:05 所属栏目:百科 来源:网络整理
导读:Idris Day 1 基本上还是Haskell的语法? *functions:t map Prelude.Functor.map: Functor f = (a - b) - (f a) - f b map (x = x * 0.5) (the (List Float) [3.14,2.78]) 数据类型:idris/day1/data_types.idr data DumbNumber = Naught | One | Two | Thre

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++类型设计?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读