Skip to content

Instantly share code, notes, and snippets.

variable {T : Type}
inductive list (T : Type) : Type :=
| nil {} : list T
| cons : T → list T → list T
open list
definition append : list T → list T → list T
| nil l := l
| (cons x xs) l := cons x (append xs l)
@myuon
myuon / MakeLense.hs
Last active February 14, 2016 15:19
{-# LANGUAGE GADTs, RankNTypes, TypeOperators, DataKinds, KindSignatures #-}
{-# LANGUAGE UndecidableInstances, FlexibleInstances, MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies, ScopedTypeVariables, TypeFamilies #-}
{-# LANGUAGE FlexibleContexts, ConstraintKinds #-}
module MakeLense (
Name(..), Proxy(..),
UnionT,
Union(..),
-- keysH, keysU, HasKey,
Has,
import Haste
import Haste.DOM
import Haste.Events
import Haste.Foreign hiding (get)
import Haste.Graphics.Canvas
import Haste.Graphics.AnimationFrame
import Control.Monad.State
import Data.IORef
import qualified Data.IntMap as IM
import Lens.Family2
{-# LANGUAGE TypeFamilies, DataKinds, TypeOperators, FlexibleInstances #-}
import GHC.TypeLits
type family FuncType (as :: [*]) where
FuncType '[] = IO ()
FuncType (a ': as) = a -> FuncType as
data Name (s :: Symbol) = Name
@myuon
myuon / PFAD.thy
Created August 4, 2015 07:45
PFAD, Chapter 1-1
theory PFAD
imports Main
begin
fun maximum where
"maximum xs = foldr max xs 0"
lemma maximum_larger: "xs ≠ [] ⟹ (⋀x :: nat. x ∈ set xs ⟹ x ≤ maximum xs)"
proof (induct xs, simp, auto)
fix a :: nat and xs :: "nat list" and x
@myuon
myuon / NSemiring.hs
Created July 21, 2015 13:44
Near Sermiring and MonadPlus
{-# LANGUAGE Rank2Types, ScopedTypeVariables #-}
import Prelude hiding ((<*>), abs)
import qualified Control.Applicative as A
import Control.Monad
import Test.QuickCheck
class NearSemiring m where
(<+>) :: m a -> m a -> m a
zero :: m a
(<*>) :: m a -> m a -> m a
@myuon
myuon / Category.thy
Last active August 29, 2015 14:25
setoid construction
theory Category
imports Main
begin
no_notation Fun.comp (infixl "∘" 55)
lemma equiv_refl: "equiv A R ⟹ x ∈ A ⟹ (x,x) ∈ R"
by (rule equivE, simp, rule refl_onD, simp)
lemma equiv_sym: "equiv A R ⟹ (x,y) ∈ R ⟹ (y,x) ∈ R"
@myuon
myuon / Extensible0.hs
Created July 17, 2015 05:07
Recordを剥がして連結しただけ
{-# LANGUAGE TypeFamilies, DataKinds, TypeOperators, PolyKinds, UndecidableInstances, TemplateHaskell, FlexibleContexts, AllowAmbiguousTypes #-}
import Control.Lens
import Data.Extensible
import Data.Extensible.Internal
import GHC.TypeLits
type family GetList r :: [Assoc Symbol *] where
GetList (h :* xs) = xs
@myuon
myuon / Main.hs
Last active June 17, 2019 18:29
Lens from Scratch
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, Rank2Types #-}
import Control.Applicative
import Control.Monad
import Data.Functor.Identity
import Data.Foldable
import Data.Monoid
import Data.Tagged
class Profunctor p where
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d
@myuon
myuon / Main.hs
Last active August 29, 2015 14:24
Grand Millionaire
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Lens
import Control.Monad.State
import Control.Monad.Except
import Data.Char
import Data.List
import qualified Data.IntMap as IM
import Data.List.Split (chunksOf)