Skip to content

Instantly share code, notes, and snippets.

View viercc's full-sized avatar

Koji Miyazato viercc

View GitHub Profile
@viercc
viercc / hand_exec.txt
Last active December 16, 2015 14:29
Hand execution trace of GaborSch's algorithm applied to input {20}
In here, I will write each node as
[weight]number=expr
and, as a compact notation, multiple nodes with same weight
[w]n1=e1 [w]n2=e2 [w]n3=e3
are denoted
[w]n1=e1 n2=e2 n3=e3
I will trace execution of your algorithm applied to input {20}.
First, I register [0]1 and generate [1]2=1+1
@viercc
viercc / NatSet.hs
Created April 24, 2013 10:01
Related to: http://stackoverflow.com/questions/16128645/ Haskell source file I implemented the algorithm which is written in the question.
-- Related to: http://stackoverflow.com/questions/16128645/
-- Haskell source file I implemented the algorithm which is written in the question.
-- this program is written under GHC 7.4.2 @ Ubuntu 12.10,
-- requires mtl (Monad transformers) module.
-- To test this:
-- * place this file on a directory
-- * run GHCi there
-- * load NatSet module (:load NatSet)
-- * give some list of Int to printClosure function.
-- example: > printClosure [7, 20, 17, 100]
-- simple test for NatSet.hs
--
-- I did the performance test by running
-- $ time ./natset_perf
-- command, where natset_perf is compiled executable of this code.
import NatSet
import System.Random
import Control.Monad (forM_)
@viercc
viercc / Domain.v
Last active December 30, 2015 17:19
http://d.hatena.ne.jp/m-hiyama/20081024/1224814465 で紹介された、Seven Trees Puzzleの答えとなる全単射を、全単射であるという証明付きで構成する
(* definition of Tree *)
Inductive Tree : Set :=
| leaf : Tree
| node : Tree -> Tree -> Tree.
(* definition of Domain *)
Inductive Domain : Set :=
| I : Domain
| T : Domain
| sum : Domain -> Domain -> Domain
@viercc
viercc / SetMonad.hs
Created December 3, 2017 14:10
My take on Set Monad
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-|
Module : SetMonad
Description : Set that is also Monad
This module provides the @Set@ type equipped with @Monad@ instance and most of set
operations provided in the @Data.Set@ module of @containers@ package.
The ability to handling any type is not \"free\". If there is no clue
@viercc
viercc / Main.hs
Last active December 15, 2017 12:21 — forked from anonymous/Main.hs
GHC 8.2.2 allows bang patterns in let binding without -XBangPatterns
--{-# LANGUAGE BangPatterns #-}
module Main where
main :: IO ()
main = putStrLn "Compiles"
letBangPattern :: Int
letBangPattern = let !x = 1 + 2 in x
@viercc
viercc / ApplicativeLaw
Last active January 8, 2018 10:22
ShrinkOnce.hs
Applicative laws (in terms of 'prod'):
prod :: Applicative f => f a -> f b -> f (a,b)
prod = liftA2 (,)
(1) Left unit:
pure a `prod` fb = fmap (a,) fb
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Data.Matchable(
-- * Matchable class
Matchable(..),
zipzipMatch,
traverseDefault,
eqDefault,
@viercc
viercc / pairing-functor.lhs
Created June 23, 2018 07:53
I asked a silly question at StackOverflow long ago. This was preparation of the question & self-resolve.
During play around objective package, I noticed following type has interesting property.
> {-# LANGUAGE RankNTypes #-}
> {-# LANGUAGE GADTs #-}
> {-# LANGUAGE TypeOperators #-}
> {-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
> {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
> {-# LANGUAGE UndecidableInstances #-}
>
> import Control.Monad
@viercc
viercc / AdHocInstances.hs
Created June 23, 2018 07:54
Defining a instance of class without declaring newtype or instance declaration.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UndecidableInstances #-}
module AdHocInstances(
Group(..),
GroupExpr(),
adhocGroup
) where