Skip to content

Instantly share code, notes, and snippets.

@rxin
rxin / ByteBufferPerf.scala
Last active May 14, 2018 21:27
Comparison of performance over various approaches to read Java ByteBuffer. The best way is to use Unsafe, which also enables reading multiple primitive data types from the same buffer.
/**
* To compile:
* scalac -optimize ByteBufferPerf.scala
*
* JAVA_OPTS="-Xmx2g" scala IntArrayPerf 10
* 49 62 48 45 48 45 48 50 47 45
*
* JAVA_OPTS="-Xmx2g" scala ByteBufferPerf 10
* 479 491 484 480 484 481 477 477 472 473
@kazu-yamamoto
kazu-yamamoto / gist:5218431
Last active July 22, 2022 13:44
Purely functional Dijkstra algorithm using priority search queue to find shortest paths
-- % cabal install PSQueue
-- % ghci Dijkstra.hs
-- > dijkstra sample A
-- [(A,0,A),(D,4,A),(E,7,D),(C,8,E),(B,9,E)]
module Dijkstra where
import Control.Applicative hiding (empty)
import Data.List (unfoldr)
import Data.Maybe (fromJust)
@pthariensflame
pthariensflame / IndexedCont.md
Last active April 3, 2022 00:30
An introduction to the indexed continuation monad in Haskell, Scala, and C#.

The Indexed Continuation Monad in Haskell, Scala, and C#

The indexed state monad is not the only indexed monad out there; it's not even the only useful one. In this tutorial, we will explore another indexed monad, this time one that encapsulates the full power of delimited continuations: the indexed continuation monad.

Motivation

The relationship between the indexed and regular state monads holds true as well for the indexed and regular continuation monads, but while the indexed state monad allows us to keep a state while changing its type in a type-safe way, the indexed continuation monad allows us to manipulate delimited continuations while the return type of the continuation block changes arbitrarily. This, unlike the regular continuation monad, allows us the full power of delimited continuations in a dynamic language like Scheme while still remaining completely statically typed.

@gakuzzzz
gakuzzzz / article.md
Last active October 29, 2019 06:19
「Javaで継続モナド」をScalaに翻訳/Scala Advent Calendar 2013

「Javaで継続モナド」をScalaに翻訳

この記事はScala Advent Calendar 2013の7日目の記事です。

昨日は @shogogg さんのScala + sbt-android + IntelliJ で快適Androidアプリ開発でした。

明日は @takezoux2 さんのScalaのParserCombinator実践入門+です。

継続モナドを調べていたら、@terazzo さんのJavaで継続モナドという記事が非常に判りやすかったんですが、サンプルコードがJavaのボイラープレートの嵐でちょっと読むのが辛い感じだったのでScalaで翻訳してみました、というのがこの記事です。

@leque
leque / gist:8035729
Last active December 31, 2015 19:49

各言語のコレクション操作高階関数(メソッド、手続き)

Language
Common Lisp mapc mapcar find-if remove-if-not reduce reduce :from-end t some every
Scheme for-each map find filter fold, fold-left fold-right any, exists every, for-all
Haskell mapM_ map find filter foldl foldr any all
Caml Light do_list map - - it_list list_it exists for_all
OCaml iter map find filter, find_all fold_left fold_right exists for_all
F# iter map find filter fold foldBack exists forall
@gakuzzzz
gakuzzzz / 1_.md
Last active August 2, 2023 01:59
Scala の省略ルール早覚え

Scala の省略ルール早覚え

このルールさえ押さえておけば、読んでいるコードが省略記法を使っていてもほぼ読めるようになります。

メソッド定義

def concatAsString(a: Int, b: Int): String = {
  val a_ = a.toString();
  val b_ = b.toString();
Inductive Term : Set :=
| T
| F
| TIf (_ : Term) (_ : Term) (_ : Term).
Inductive Step : Term -> Term -> Prop :=
| EIfTrue : forall (t1 t2 : Term), Step (TIf T t1 t2) t1
| EIfFalse : forall (t1 t2 : Term), Step (TIf F t1 t2) t2
| EIf : forall (t1 t1' t2 t3 : Term), Step t1 t1' -> Step (TIf t1 t2 t3) (TIf t1' t2 t3).
@mzp
mzp / gist:ebbd01613736beda61bd
Last active August 29, 2015 14:13
SML# contrib.md

目標

see: https://github.com/bleis-tift/SmlSharpContrib

SML#のライブラリが足りないのでなんとかしたい。

方針(検討中)

  • こったライブラリにはしない
  • 適当なCライブラリの薄いラッパにする
  • メソッドはすべて移植する(よっぽど不要なやつは省く?)
@Gab-km
Gab-km / papylon_doc.ja.rst
Last active December 8, 2015 03:08
ぱぴろん非公式ドキュメント

ぱぴろん非公式ドキュメント

ぱぴろんとは?

ぱぴろん(Papylon)は、満たすべき性質(property)を記述することでテストケースを自動生成する Python 用テスティングツールです。いわゆる"QuickCheck"系の流れを汲み、 FsCheckScalaCheck の影響を強く受けています。テストしたい対象の振る舞うべき性質を記述して実行すると、テストケースをランダムに生成して実行し、性質が成り立つかどうかを確認します。

簡単な例

@xuwei-k
xuwei-k / scalaz-stream.md
Last active June 24, 2021 01:09
Scalaz-Streamの基本的なクラスや概念まとめ

Scalaz-Streamの基本的なクラスや概念まとめ

  • versionは0.7a

scalaz-streamが依存してるライブラリ内のclass

  • scalaz-streamではなくscalaz-concurrentにあるクラス
  • scalaz-streamは、これと Task にかなり依存してるので、まずはこれらを理解することが重要