Skip to content

Instantly share code, notes, and snippets.

(ns dsls.core)
(def x 4)
(comment
"Delaying evaluation with Quote"
x
'x
{-# LANGUAGE OverloadedStrings #-}
module Parsing.Examples where
import Data.Attoparsec.Text
import Control.Applicative
something :: Parser (String, Maybe String)
something =
do a <- manyTill anyChar (string "--") <|> many anyChar
(add-hook 'haskell-mode-hook (lambda () (run-with-idle-timer (seconds-to-time 1) t 'ghc-show-type)))
@zerokarmaleft
zerokarmaleft / Monoid.hs
Last active August 29, 2015 14:02 — forked from puffnfresh/Monoid.rs
Semigroups and Monoids
class Semigroup a where
mappend :: a -> a -> a
class Semigroup a => Monoid a where
mempty :: a
mconcat :: [a] -> a
mconcat = foldr mappend mempty
instance Semigroup Int where
(defn parse-necronomemoticon
[s]
(let [rdr (BufferedReader. (StringReader. s))
expr (->> (line-seq rdr) (map seq) first)]
(match [expr]
[([\( \; \, \; \)] :seq)] :evil
:else :failure)))
module Untyped.Context where
type Context = [String]
mkContext :: Context
mkContext = []
bindVarName :: Context -> String -> Context
bindVarName ctx x = x : ctx
{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, DeriveGeneric #-}
module Main where
import Data.Aeson.Types
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.UTF8 as UTF8
import GHC.Generics
import Network.Riak
{-# LANGUAGE DeriveGeneric
, FlexibleInstances
, OverloadedStrings
, ScopedTypeVariables
, TypeSynonymInstances #-}
module Main where
import Control.Monad
import Data.Aeson.Types
var Lazy = require('lazy.js');
function isHeads(x) { return x >= 0.5; }
function isTails(x) { return x < 0.5; }
function toss(n) {
var successes = Lazy.generate(function() { return Math.random(); })
.take(n)
.filter(isHeads)
.size();
@zerokarmaleft
zerokarmaleft / memoization.py
Created September 10, 2014 20:18
Memoization is a performance optimization, not a means to achieve referential transparency
# Memoization doesn't get you all the way there. While a memoized
# function might exhibit referential transparency *at two successive
# callsites*, your program as a whole will not exhibit that
# property. An example with destructive updates of a mutable data
# structure, an inherently effectful operation:
phonebook = {}
# assuming this function is augmented with memoization