Skip to content

Instantly share code, notes, and snippets.

$wbfStep :: EdgeVec -> CostVec -> Vector Dist
$wbfStep =
\ (w :: EdgeVec) (w1 :: CostVec) ->
let { Vector ipv ipv1 ipv2 ~ _ <- w1 `cast` ... } in
let { V_3 ipv3 ipv4 ipv5 ipv6 ~ _ <- w `cast` ... } in
let { Vector rb _ rb2 ~ _ <- ipv4 `cast` ... } in
let { Vector rb3 _ rb5 ~ _ <- ipv5 `cast` ... } in
let { Vector rb6 _ rb8 ~ _ <- ipv6 `cast` ... } in
runSTRep
(\ (@ s) (s :: State# s) ->
@klapaucius
klapaucius / bf.c
Last active December 11, 2015 08:28 — forked from rblaze/bf.c
win 7 x64 cpu: i7 3770 ghc: 7.4.2 x32 -O2 -fllvm llvm: 3.1 gcc: 4.5.2 -O3 (нет разницы с -O2) разница в 2.6 раза, из 90 секунд работы хаскель-версии 12% - чтение файла и построение графа в памяти.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int infinity = 2147483647;
struct edge_t {
int v1;
int v2;
int cost;
@klapaucius
klapaucius / gist:3795780
Created September 27, 2012 19:01
type-prelude
*Prelude.Type> T::T (Any ((==) 1) '[3,2,1])
True
it ::
T (Bool -> Constraint)
(Any
Nat (Nat == 1) ((':) Nat 3 ((':) Nat 2 ((':) Nat 1 ('[] Nat)))))
*Prelude.Type> T::T (Any ((==) 1) '[3,2])
False
it ::
T (Bool -> Constraint)
> :{
let merge xs [] = xs
merge [] ys = ys
merge (x:xs) (y:ys) | x < y = x: merge xs (y:ys)
| otherwise = y: merge (x:xs) ys
:}
> :set -XNoMonomorphismRestriction
> let mergeAll = foldr1 merge
> take 20 $ mergeAll [[5..],[1..],[3..],[7..],[2..],[1..]]
[1,1,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,5,6,6]
@klapaucius
klapaucius / gist:3367586
Created August 16, 2012 07:03
runtime/compile-time
Prelude> class Pet a where kill :: a -> String
Prelude> data Dog = Dog deriving Show
Prelude> data Cat = Cat deriving Show
Prelude> instance Pet Dog where kill = const "dead"
Prelude> instance Pet Cat where kill = const "c_1|dead> + c_2|alive>"
Prelude> map kill [Cat, Cat] -- диспетчеризация времени компиляции
["c_1|dead> + c_2|alive>","c_1|dead> + c_2|alive>"]
Prelude> map kill [Dog, Dog] -- диспетчеризация времени компиляции
["dead","dead"]
Prelude> data PetBox where Box :: Pet a => a -> PetBox
@klapaucius
klapaucius / gist:3357481
Created August 15, 2012 07:59
Typeable
GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> import Control.Exception
Prelude Control.Exception> import Data.Typeable
Prelude Control.Exception Data.Typeable>
newtype Foo = Foo (() -> IO ())
Prelude Control.Exception Data.Typeable> :set -XSafe
@klapaucius
klapaucius / 1.hs
Created July 4, 2012 10:47
XDefaultSignatures
Prelude Control.Monad> :set -XDefaultSignatures
Prelude Control.Monad>
newtype Box a = Box a deriving Show
Prelude Control.Monad>
instance Monad Box where
return = Box
(Box x) >>= f = f x
structure S1 = struct
fun foo (x:{cells:int list, columns:int, rows:int}) = (#columns x, #rows x, #cells x)
end;
structure S2 = struct
fun foo (x:{cells:int list, columns:int, rows:int}) = (#columns x, #rows x, #cells x)
end;
S1.foo {columns = 1, rows = 2, cells = [1,2]};
val it = (1,2,[1,2]) : int * int * int list
@klapaucius
klapaucius / foldm.hs
Created March 13, 2012 10:39
worker/wrapper
{-# OPTIONS_GHC -fstatic-argument-transformation #-}
module Main (main) where
import Criterion.Main
import Control.Monad
import Data.List
import Data.Functor.Identity
foldM' :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
mvmap f v = go $ M.length v where
go 0 = return ()
go (n + 1) = update v n f >> go n