Skip to content

Instantly share code, notes, and snippets.

@tanakh
tanakh / gist:4123137
Created November 21, 2012 05:09
Jigen-zan proto
{-# LANGUAGE DeriveFunctor, TypeFamilies, EmptyDataDecls, PolyKinds, DataKinds, ConstraintKinds #-}
newtype Dimensional (dim :: Dimension) a = Dimensional a
deriving (Eq, Ord, Show, Functor)
data Dimension = Dim0 | Dim String Int Dimension
type family Insert (a :: Dimension) (k :: String) (v :: Int) :: Dimension
type instance Insert (Dim0 k v) = Dim k v Dim0
type instance (k < a) => Insert (Dim a b l) k v = Dim k v (Dim a b l)
@tanakh
tanakh / hoge.hs
Created November 27, 2012 05:55
ADTをUnboxed Vectorにして、Lens経由でアクセスする ref: http://qiita.com/items/3a2053bea740ca423407
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import Control.Lens hiding (Rep, from, to)
@tanakh
tanakh / file0.txt
Created November 27, 2012 07:44
エクスポートモジュールの楽な追加 ref: http://qiita.com/items/dc8641a618b39e875ea1
module Foo (
module Bar,
module Baz,
...
) where
import Bar
import Baz
...
import Control.Applicative
import Control.Monad
import Data.Char
import Data.List.Split
import Data.SBV
main :: IO ()
main = do
t <- map read . words <$> getLine
case t of
@tanakh
tanakh / gist:4336485
Created December 19, 2012 12:59
15 puzzle, debugging...
import Data.SBV
godNumber :: Int
godNumber = 50
p1 :: [[SInteger]]
p1 =
[ [11, 2, 8, 5]
, [13, 14, 10, 12]
, [4, 3, 1, 7]
@tanakh
tanakh / gist:5106762
Last active December 14, 2015 15:19
verified selection sort
#include <vcc.h>
_(logic \bool sorted(int *buf, unsigned len) =
\forall unsigned i, j; i < j && j < len ==> buf[i] <= buf[j])
_(logic \bool is_minimum(int *buf, unsigned l, unsigned r, unsigned x) =
\forall unsigned i; l <= i && i < r ==> buf[x] <= buf[i])
unsigned find_min(int *v, unsigned l, unsigned r)
_(requires \thread_local_array(v, r))
@tanakh
tanakh / gist:5118111
Last active December 14, 2015 16:49
verified selection sort
#include <vcc.h>
_(logic \bool sorted(int *buf, unsigned len) =
\forall unsigned i, j; i < j && j < len ==> buf[i] <= buf[j])
_(typedef unsigned perm_t[unsigned];)
_(logic \bool is_permutation(perm_t perm, unsigned len) =
(\forall unsigned i, j;
i < j && j < len ==> perm[i] != perm[j]))
@tanakh
tanakh / gist:5123461
Created March 9, 2013 08:19
verified insertino sort by Isabelle
theory Scratch
imports Main
begin
primrec ins :: "int => int list => int list" where
"ins x [] = [x]" |
"ins x (y # ys) = (if x <= y then (x # y # ys) else (y # ins x ys))"
primrec sort :: "int list => int list" where
"sort [] = []" |
@tanakh
tanakh / gist:5128426
Created March 10, 2013 12:41
verified sort
theory Sorts
imports Main
begin
primrec insert :: "int => int list => int list" where
"insert v [] = [v]" |
"insert v (x # xs) =
(if v <= x then v # x # xs else x # insert v xs)"
primrec insert_sort :: "int list => int list" where
@tanakh
tanakh / gist:5128470
Created March 10, 2013 12:53
generated haskell code
{-# LANGUAGE EmptyDataDecls, RankNTypes, ScopedTypeVariables #-}
module Sorts where {
import Prelude ((==), (/=), (<), (<=), (>=), (>), (+), (-), (*), (/), (**),
(>>=), (>>), (=<<), (&&), (||), (^), (^^), (.), ($), ($!), (++), (!!), Eq,
error, id, return, not, fst, snd, map, filter, concat, concatMap, reverse,
zip, null, takeWhile, dropWhile, all, any, Integer, negate, abs, divMod,
String, Bool(True, False), Maybe(Nothing, Just));
import qualified Prelude;