Skip to content

Instantly share code, notes, and snippets.

@tanakh
tanakh / gist:7764127
Created December 3, 2013 05:04
新人女子にHaskellを教え込むHaskellerの鑑 https://paiza.jp/poh/ec-campaign あなたの部署に配属された新人女子プログラマの野田さんのコードをより良いものに直してください。野田さんは実はあなたの会社の社長令嬢。効率の良いコードに書き換えて、プログラマとしてのスキルをアピールできれば昇進するチャンスです。
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed ((!))
import qualified Data.Vector.Algorithms.Intro as Intro
isort v = runST $ do
import Criterion.Main
import Data.List
f :: Int -> Int
f n = foldl1' (+) $ zipWith (+) [1..n] [1..n]
main = defaultMain
[ bgroup "map"
[ bench "map" $ whnf f 1000000
]

Markdown Editor

Poppen's Lab


##What

This is Markdown editor.

@tanakh
tanakh / Tree.hs
Last active December 14, 2015 21:19
Haskell Code Verification
module Tree where
data Tree a
= Tip
| Node (Tree a) a (Tree a)
mirror :: Tree a -> Tree a
mirror Tip = Tip
mirror (Node l v r) = Node (mirror r) v (mirror l)
@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;
@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: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: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: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: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]