Skip to content

Instantly share code, notes, and snippets.

@callumacrae
callumacrae / rand.js
Created March 29, 2013 12:52
Random number generator.
/**
* Returns random numbers. See individual functions for docs.
*
* This function can be used as a shortcut function: by default, it will call
* rand.int() using the arguments given to it. You can change which method it
* will call by changing the rand.default string to any of the method names.
*/
function rand(length) {
"use strict";
@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.

@thoughtpolice
thoughtpolice / CoYoneda.hs
Last active December 27, 2019 01:52
CoYoneda = Yoneda
{-# LANGUAGE ExistentialQuantification, RankNTypes #-}
{-# LANGUAGE InstanceSigs #-}
module CoYoneda where
import Data.IORef
import Data.Set (Set, map)
import Control.Monad (liftM)
--------------------------------------------------------------------------------
-- Yoneda
@thoughtpolice
thoughtpolice / CoYoOperational.hs
Last active December 17, 2017 23:46
Free (CoYoneda f) ~ Operational
{-# LANGUAGE GADTs, LambdaCase, MultiParamTypeClasses, FlexibleInstances #-}
-- |
-- Module : Control.Operational.Monad
-- Copyright : (c) Austin Seipp 2013
-- License : BSD3
--
-- Maintainer : [email protected]
-- Stability : experimental
-- Portability : unportable (GADTs, MPTCs, etc)
--
@CMCDragonkai
CMCDragonkai / angularjs_directive_attribute_explanation.md
Last active April 20, 2025 17:02
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
@alucky0707
alucky0707 / defer.hs
Created October 8, 2013 14:47
HaskellでGo言語のdefer文してみる with Freeモナド ref: http://qiita.com/alucky0707/items/156b2b013e16f27cb8d0
{-# LANGUAGE DeriveFunctor, LambdaCase #-}
import Control.Monad
import Control.Monad.Trans
import Control.Monad.Trans.Free
import System.IO
type Defer m = FreeT (DeferF m) m
data DeferF m cont
@sjoerdvisscher
sjoerdvisscher / profunctorlens.hs
Last active October 1, 2017 21:42
Pure profunctor lenses
{-# LANGUAGE Rank2Types #-}
import Control.Applicative (Applicative(..), (<$>), Const(..))
import Control.Lens.Internal.Review (Reviewed(..))
import Control.Lens.Internal.Bazaar (Bazaar(..))
import Data.Monoid (Monoid(..), First(..))
import Data.Profunctor
import Data.Profunctor.Rep
import Data.Functor.Identity
@nadult
nadult / parser.hs
Created November 3, 2013 11:38
C-like language parser in Haskell.
module Parser(parseProgram) where
import Text.Parsec.Expr
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Error
import qualified Text.ParserCombinators.Parsec.Token as P
import Text.ParserCombinators.Parsec.Language
import Control.Monad
import Tokens
@MgaMPKAy
MgaMPKAy / SimpleStateMonad.hs
Last active November 2, 2019 18:59
Trampolined state monad in Haskell, translated from RO Bjarnason's Stackless Scala With Free Monads,
newtype State s a = State {runS :: s -> (a, s)}
instance Monad (State s) where
return x = State $ \s -> (x, s)
ma >>= f = State $ \s -> let (a, s1) = runS ma s
in runS (f a) s1
get = State $ \s -> (s, s)
put x = State $ \_ -> ((), x)
@philopon
philopon / eff-test.hs
Created January 16, 2014 08:36
extensible-effectsでいろいろ試した。
{-#LANGUAGE NoMonomorphismRestriction, DeriveDataTypeable, TypeOperators#-}
import Control.Applicative
import Control.Monad
import Control.Concurrent (threadDelay)
import Control.Eff
import Control.Eff.State.Strict
import Control.Eff.Lift
import Control.Eff.Fail