Skip to content

Instantly share code, notes, and snippets.

let quickSort (a:_[]) =
let rec f _l _r =
if _l < _r then
let mutable l, r, p =_l, _r, a.[_l]
while l <= r do
while a.[l] < p do l <- l + 1
while a.[r] > p do r <- r - 1
if l <= r then
let t = a.[l]
a.[l] <- a.[r]
{-# LANGUAGE GADTs, DataKinds, TypeFamilies, ConstraintKinds, TypeOperators, UndecidableInstances, ExistentialQuantification #-}
import GHC.Prim (Constraint)
import Data.Ratio ((%))
type family All (cx :: * -> Constraint) (xs :: [*]) :: Constraint
type instance All cx '[] = ()
type instance All cx (x ': xs) = (cx x, All cx xs)
data HList (as :: [*]) where
open System
let rec pown x y cont =
if y = 1I then cont x else
let cont = if y &&& 1I = 0I then cont else (*) x >> cont
pown (x*x) (y>>>1) cont
let memo = Collections.Generic.Dictionary()
let rec A (m:int, n:bigint, cont) =
if memo.ContainsKey (m, n) then cont memo.[(m,n)]
elif m < 2 then cont (n + 1I + bigint m)
function findImage (mp) {
var url = "./data/" + mp.folder + "/" + mp.storage;
["", ".jpg", ".png"].map(function(ext) {
$("<img/>")
.load(function() { mp.storage = mp.storage + ext; })
.attr("src", url + ext);
});
}
open System
let inline check< ^a> list =
list |> List.iter (fun (name,func: ^a seq ->_) ->
try func Seq.empty< ^a> |> ignore
with e -> printfn "Seq.%s: %A" name e.Message)
check<float> [
"average", Seq.average
"averageBy", Seq.averageBy id
[macro name="Macro1"]
[call target=*scriptMacro1]
[endmacro]
[jump target=*nextMacro1]
*scriptMacro1
[iscript]
..
[endscript]
[return]
@nagat01
nagat01 / gist:086bbcdf28c46706a345
Created May 8, 2014 21:00
吉里吉里のtjsのisDefined.tjs
function isDefined(x) { return x != "undefined" && typeof x !== "undefined"; }
open System
open System.Threading
// 進捗を通知する処理を組み立てるビルダーのベースになります
type ProgressBaseBuilder () =
// calculation は時間のかかる計算で、第1引数は進捗があった時のコールバックです
member this.Bind((weight, calculation), remaining) =
calculation
(fun rate -> rate * weight |> this.report) // 進捗率 x 重み の進捗があったことを通知します
open FSharp.Charting
open System.Windows.Forms.Integration
let hostChart chart = new WindowsFormsHost(Child = new ChartTypes.ChartControl(chart))
open System
open System.Threading
let heavyFuncBase name func v listener =
printfn "\r\n%s started..(result = %d)" name v
for i in 1..10 do Thread.Sleep 10; listener 0.1
func v
let heavyFuncA = heavyFuncBase "A" id 1
let heavyFuncB = heavyFuncBase "B" (fun a -> a + 10)