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++类型设计?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值