Skip to content

Instantly share code, notes, and snippets.

View cutsea110's full-sized avatar

cutsea110 cutsea110

View GitHub Profile
@cutsea110
cutsea110 / Test.hs
Created July 26, 2012 08:47
てすと
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE RankNTypes #-}
module Test where
data X = X String
deriving Show
type Y = Int
class Z a where
@cutsea110
cutsea110 / Test2.hs
Created July 26, 2012 09:16
:t zがダメだけど、D (X "123") 123 (1::Y)やD (X "123") 123 (X "456")ではデータ構築可能
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTs #-}
module Test where
data X = X String
deriving Show
type Y = Int
{-# LANGUAGE FlexibleInstances, ImplicitParams #-}
import Control.Monad
import Control.Applicative
instance (Monad m, Num b) => Num (a -> m b) where
a + b = liftM2 (+) <$> a <*> b
a * b = liftM2 (*) <$> a <*> b
negate a = liftM negate <$> a
abs a = liftM abs <$> a
signum a = liftM signum <$> a
{-# LANGUAGE NoMonomorphismRestriction #-}
module Test where
import Control.Applicative ((<$>),(<*>))
import Control.Monad.State (get, put, lift, StateT(..))
import Control.Monad.Trans.Either (right, left, EitherT(..))
type C a = EitherT String (StateT [a] IO)
-- low level
@cutsea110
cutsea110 / gist:83a50af4f8ed41a97a85
Created July 9, 2015 08:48
BCoPL exercise 1-3 (1)(2)
ex-1-3-1 : ∀ {n₁ n₂ n₃} → (p : n₁ plus n₂ is n₃) → steps-plus p ≡ 1 + n₁
ex-1-3-1 P-Zero = refl
ex-1-3-1 (P-Succ p) = cong S (ex-1-3-1 p)
ex-1-3-2 : ∀ {n₁ n₂ n₃} → (p : n₁ times n₂ is n₃) → steps-times p ≡ 1 + n₁ * (n₂ + 2)
ex-1-3-2 T-Zero = refl
ex-1-3-2 (T-Succ t p) = cong S (plus+times≡n₂+2+n₁[n₂+2] t p)
where
S[a+Sb]≡a+2+b : (a b : ℕ) → S (a + S b) ≡ a + 2 + b
S[a+Sb]≡a+2+b Z b = refl
module Test where
open import Data.Bool
open import Data.Char hiding (_==_)
open import Data.String hiding (_==_)
record Eq (A : Set) : Set₁ where
field
_==_ : A → A → Bool
-- theorem 2.5
associativity-plus : ∀ {n₁ n₂ n₃ n₄ n₅} → n₁ plus n₂ is n₄ → n₄ plus n₃ is n₅ →
∃ λ n₆ → n₂ plus n₃ is n₆ → n₁ plus n₆ is n₅
associativity-plus {Z} {Z} {Z} {Z} {Z} P-Zero P-Zero = Z , (λ x → x)
associativity-plus {Z} {Z} {Z} {Z} {S n₅} P-Zero ()
associativity-plus {Z} {Z} {Z} {S n₄} {Z} () l₂
associativity-plus {Z} {Z} {Z} {S n₄} {S n₅} () l₂
associativity-plus {Z} {Z} {S n₃} {Z} {Z} P-Zero ()
associativity-plus {Z} {Z} {S n₃} {Z} {S .n₃} P-Zero P-Zero = S n₃ , (λ x → x)
associativity-plus {Z} {Z} {S n₃} {S n₄} {Z} () l₂
-- theorem 2.5
associativity-plus : ∀ {n₁ n₂ n₃ n₄ n₅} → n₁ plus n₂ is n₄ → n₄ plus n₃ is n₅ →
∃ λ n₆ → n₂ plus n₃ is n₆ → n₁ plus n₆ is n₅
associativity-plus {Z} {Z} {Z} {Z} {Z} P-Zero P-Zero = Z , id
associativity-plus {Z} {Z} {Z} {Z} {S n₅} P-Zero ()
associativity-plus {Z} {Z} {n₄ = S n₄} () l₂
associativity-plus {Z} {Z} {S n₃} {Z} {Z} P-Zero ()
associativity-plus {Z} {Z} {S n₃} {Z} {S .n₃} P-Zero P-Zero = S n₃ , id
associativity-plus {Z} {S n₂} {n₄ = Z} () l₂
associativity-plus {Z} {S n₂} {n₄ = S .n₂} {n₅ = Z} P-Zero ()
@cutsea110
cutsea110 / coprime
Created December 2, 2015 07:00
coprime-lemma
module kyoin-test where
open import Data.Bool.Properties
open import Data.Nat
open import Data.Nat.Properties.Simple
open import Data.Nat.Coprimality as Coprime
open import Data.Nat.Divisibility
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Nullary.Sum
@cutsea110
cutsea110 / ex.agda
Last active November 16, 2016 17:00
ET.agda?
module ex where
open import Level using (Level) renaming (suc to lsuc)
open import Data.Bool using (Bool; true; false)
open import Data.Nat
open import Data.Maybe using (Maybe; just; nothing)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; _≢_)
open import Relation.Nullary using (Dec; yes; no)
open import Data.Unit using (⊤; tt)