Skip to content

Instantly share code, notes, and snippets.

View shhyou's full-sized avatar
💭
Alive

shuhung shhyou

💭
Alive
View GitHub Profile
@shhyou
shhyou / stlc-typeinf-infinite-loop.hs
Last active December 20, 2015 11:09
An type inference program for HM-system lambda calculus. to be checked later...
{-# LANGUAGE FlexibleContexts #-}
{-
runSolve (Arrow (TypeVar 0) (TypeVar 1)) (Arrow (TypeVar 1) (TypeVar 0))
runSolve (Arrow IntType (TypeVar 1)) (Arrow (TypeVar 0) (TypeVar 0))
runSolve (Arrow (Arrow (TypeVar 0) (TypeVar 1)) (TypeVar 2)) (Arrow (TypeVar 3) (Arrow (TypeVar 4) (TypeVar 5)))
runSolve (TypeVar 0) (Arrow (TypeVar 0) (TypeVar 1))
runSolve (TypeVar 0) (Arrow (TypeVar 1) (TypeVar 0))
@shhyou
shhyou / extensible-union-test.hs
Created August 17, 2013 15:49
keywords: open union, extensible union, extensible datatypes
{-# LANGUAGE RankNTypes, KindSignatures, TypeOperators, GADTs, ScopedTypeVariables,
FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, OverlappingInstances #-}
import Data.Functor
import Control.Applicative -- for several functor instances
-- open union
infixr 1 :>
data (a :: * -> *) :> b
@shhyou
shhyou / cps-partial-evaluated.ss
Last active December 21, 2015 16:39
CPS transform program with some basic simplifications.
; See also: https://github.com/yinwang0/old-toys/blob/master/cps.ss
(load "prelude.ss")
;; Syntax:
;; e ::= x
;; | c
;; | (lambda (x ...) e)
;; | (op2 e1 e2)
;; | (if e0 e1 e2)
@shhyou
shhyou / miniKanren-test0.ss
Last active December 23, 2015 17:39
Playing miniKanren!
; playing with miniKanren!
(load "mk.ss")
(load "mkextraforms.ss")
(load "mkprelude.ss")
; data Nat : Set where
(define nato
(lambda (n)
(conde [(zeroo n) succeed] ; zero : Nat
@shhyou
shhyou / ac2dc.hs
Last active December 24, 2015 13:39
parser of alternating current to direct current converter
module AC2DC () where
import Control.Monad (guard)
import Control.Applicative ((<$>), (<*>), (<*), (*>))
import Text.ParserCombinators.Parsec
type Id = String
data ASTree = Prog ASTree ASTree
| Dcls [ASTree] | FloatDcl Id | IntDcl Id
@shhyou
shhyou / merge-conflict.cpp
Last active December 25, 2015 20:38
merge two conflicted diff file `ver1` and `ver2` on the basis of `origin` file. Switched to C++ version.
/* http://ideone.com/wcrspw
input: <ORIGIN...>
=====
<VERSION 1...>
=====
<VERSION 2...>
=====
example:
#lang racket
(require parser-tools/lex
(prefix-in : parser-tools/lex-sre) ; prefix RE operators by `:`
racket/match
racket/format)
;;;;;;;;;;;;;;; regular expressions ;;;;;;;;;;;;;;;
(define-lex-abbrevs
(:letter (:or (char-range "A" "Z") (char-range "a" "z")))
@shhyou
shhyou / numeral.agda
Created October 25, 2013 18:51
Finding predecessor (or, destructors?) of Church Numerals using the relation outT = (| F inT |)
module numeral where
infixl 40 _∘_
infixr 60 1+ⁿ_
-- small prelude
_∘_ : {A B C : Set} → (B → C) → (A → B) → A → C
f ∘ g = λ x → f (g x)
data ℕ : Set where
@shhyou
shhyou / inj-list-sugared.hs
Created November 17, 2013 04:22
Typeclass hacks to automatically injects elements into a list
{-# LANGUAGE FlexibleInstances #-}
data AllType = TypeA Char
| TypeB String
| TypeC Bool
deriving (Show)
newtype S = S { unS :: String }
data Ii = Ii { runIi :: [AllType] }
@shhyou
shhyou / compile13hw-Homework3.hs
Created November 17, 2013 18:01
gv printing codes
{-# LANGUAGE FlexibleContexts #-}
module Language.BLang.Homework.Homework3 (
AST,
printAST,
fromAST
) where
import Control.Monad (mapM, when)
import Control.Monad.State (MonadState, MonadIO, liftIO, runStateT, get, modify)