Skip to content

Instantly share code, notes, and snippets.

View yoshihiro503's full-sized avatar

YOSHIHIRO Imai yoshihiro503

View GitHub Profile
@yoshihiro503
yoshihiro503 / AlternativeClausesType.scala
Created May 11, 2017 02:29
すごいE本の30.6章の「選択的な節を持つ型」 (p.538) をScalaでも
// すごいE本の30.6章の「選択的な節を持つ型」 (p.538) をScalaでも
object AlternativeClausesType {
def main() = {
val List(_, _) = convert(('a, 'b))
val (_, _) = convert(List('a, 'b))
val List(_, _) = convert(List('a, 'b)) // <- 型エラーにできる
val (_, _) = convert(('a, 'b)) // <- 型エラーにできる
}
def convert(xy: (Symbol, Symbol)): List[Symbol] = xy match {
@yoshihiro503
yoshihiro503 / 練習問題: ★★★★, optional (true_upto_n__true_everywhere)
Created May 21, 2016 08:07
練習問題: ★★★★, optional (true_upto_n__true_everywhere)
Fixpoint true_upto_n__true_everywhere
(* FILL IN HERE *)
Example true_upto_n_example :
(true_upto_n__true_everywhere 3 (fun n => even n))
= (even 3 -> even 2 -> even 1 -> forall m : nat, even m).
Proof. reflexivity. Qed.
import scala.reflect.ClassTag
class EqualsWithOnlySameType[A <: EqualsWithOnlySameType[A] : ClassTag) {
override def equals(other: Any): Boolean = {
other match {
case (otherA: A) => super.equals(otherA)
case _ => throw new RuntimeException(s"異なる型同士の比較を禁止しています: $this.equals($other)")
}
}
}
val tup22 = (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
val ((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v), w) = (tup22, "hoge")
(**
* 自然数の二進表現
* 例: (10010) は O I O O I Z
* 一つの数の表現が一意でないことに注意
*)
Inductive bin_numb :=
| I : bin_numb -> bin_numb
| O : bin_numb -> bin_numb
| Z : bin_numb.
Require Import Program Arith.
(** * リストモジュールの拡張 *)
Module List.
Require Export List.
Fixpoint _index_of_loop {A:Type} (eq_dec : forall (x y:A),{x=y}+{x<>y}) a xs i :=
match xs with
| nil => None
| x::xs => if eq_dec x a then Some i else _index_of_loop eq_dec a xs (S i)
@yoshihiro503
yoshihiro503 / Otoshiana.v
Created August 28, 2015 10:33
なぞなぞ:Coqの関数定義でなぜか戻り値がSetじゃないとダメと起こられる例:
Definition foo (b : bool) : nat =
if b then 0 else 1.
@yoshihiro503
yoshihiro503 / Ninja.v
Created August 13, 2015 11:13
Coqでもあのニンジャパターンマッチが使えるぜ ref: http://qiita.com/yoshihiro503/items/c83fb2a6e2a6318db108
let '(x, y, z) := (1, 2, 3) in
...
@yoshihiro503
yoshihiro503 / Make
Last active August 29, 2015 14:27
coqdocで日本語を含むPDFを生成する ref: http://qiita.com/yoshihiro503/items/2e3035cc602301c7c9fc
-R src JapaneseCoqdocSampleProject
src/Hoge.v
src/Piyo.v
-custom "platex Proof.tex; platex Proof.tex" "Proof.tex $(VOFILES) $(VFILES:.v=.tex)" "Proof.dvi"
-custom "dvipdfmx Proof.dvi" "Proof.dvi" Proof.pdf
@yoshihiro503
yoshihiro503 / logical_example.v
Last active August 29, 2015 14:25
AffeldtさんのSsreflect練習問題exo4 ref: http://qiita.com/yoshihiro503/items/bd142fdb69c1fd64ab86
Lemma exo4 : False \/ True.
Proof.
right. exact I.
Qed.