Skip to content

Instantly share code, notes, and snippets.

@vagarenko
vagarenko / Unboxed.hs
Created November 17, 2015 15:47
Unboxed polymorphic types
{-# LANGUAGE UnboxedTuples, MagicHash, TypeFamilies, DataKinds, PolyKinds, TypeOperators, DefaultSignatures #-}
{-# LANGUAGE KindSignatures, FlexibleInstances, FlexibleContexts #-}
{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
module Data.Unboxed where
import GHC.Exts
import GHC.Generics
@vagarenko
vagarenko / CheckedRevisited.hs
Created June 18, 2016 22:04 — forked from edsko/CheckedRevisited.hs
Lightweight checked exceptions in Haskell without `unsafeCoerce`
{-# OPTIONS_GHC -Wall -fno-warn-unused-binds #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
#if __GLASGOW_HASKELL__ >= 708
{-# LANGUAGE RoleAnnotations #-}
#endif
{-# LANGUAGE BangPatterns #-}
module Main where
import qualified Data.Text as Text
import Data.Text (Text, pack)
import Criterion.Main
import Test.QuickCheck.Arbitrary
import Test.QuickCheck
import Data.List
import qualified Data.Vector.Unboxed as U
@vagarenko
vagarenko / FreeCamera.hs
Last active December 16, 2017 20:15
Free camera controller from my 3D application. Depends on `reactive-banana>=1.1` and `static-tensor>=0.2.1`
{-# LANGUAGE
TypeInType
, ExplicitForAll
, ScopedTypeVariables
, RecursiveDo
, TypeApplications
, TemplateHaskell
, FlexibleInstances
, MultiParamTypeClasses
, TypeFamilies
@vagarenko
vagarenko / maybe.ts
Last active November 6, 2022 06:50
Maybe type in Typescript.
/**
* The Maybe type encapsulates an optional value.
*/
export class Maybe<T> {
/** Create an empty value. */
static nothing<T>(): Maybe<T> {
return new Maybe<T>(undefined);
}
/** Create a non-empty value. */
@vagarenko
vagarenko / behavior.ts
Created February 5, 2018 12:22
Implementation of Functional Reactive Programming (FRP) concept of Behavior in Rx.js
import { BehaviorSubject, Observable, IDisposable } from 'rx';
/**
* Behavior represents a value that varies in time.
* Behavior is similar to `BehaviorSubject` because it always has value,
* but it's not `Subject`, that is you can't push values into it whenever you want.
* You can only subscribe it to an Observable once.
*/
export class Behavior<T> implements IDisposable {
/** Create a behavior that never changes. */