Skip to content

Instantly share code, notes, and snippets.

@takeoutweight
takeoutweight / Main.hs
Created June 27, 2014 02:55
Haste might seem like it has TCO, but it doesn't.
{-# LANGUAGE BangPatterns #-}
module Main where
-- This is constant space. Haste's Inlining (via GHC frontend) seems to
-- be able to combine even+odd to give us a single, tail-recursive loop.
even' :: Int -> Bool
even' 0 = True
even' !x = odd' (x - 1)
@takeoutweight
takeoutweight / gist:14e2594120cd29f65860
Last active August 29, 2015 14:00
Macro expansion in match rules?
;match.clj 1764
(defn to-pattern-row
"Take an unprocessed pattern expression and an action expression and return
a pattern row of the processed pattern expression plus the action epxression."
[pat action]
(let [ps (map emit-pattern (map macroexpand (group-keywords pat)))]
(pattern-row ps action)))
(defmacro single-jeopardy [c-idx q-idx]
mkdir ~/.haste
cp -r include ~/.haste/
haste-pkg update libraries/rts.pkg
ghc-pkg describe Cabal | haste-pkg update - --force
# ... in 'libraries/ghc-prim'
haste-inst --unbooted configure
&& haste-inst build --unbooted --install-jsmods --ghc-options=-DHASTE_HOST_WORD_SIZE_IN_BITS=64
&& haste-install-his ghc-prim-0.3.0.0 dist/build
@takeoutweight
takeoutweight / gist:6311241
Created August 22, 2013 18:51
Using a Reactive Contexts to work with reactive values in first-order expressions without lifts or combinators
behave1 = ...//some FRP behaviour of Number
behave2 = ...//some FRP behaviour of Number
behave3 = ReaCtx.with(function(re) {
if (re.val(behave1) < 50) {
return re.val(behave2) + 1000;
} else {
return 3;
}
});
(ns parse2
(:refer-clojure :exclude [char])
(:require [clojure.core :as core]
[clojure.string :as str]
[clojure.java.io :as io]
[zetta.core :as z]
[zetta.parser.seq :as s]
[zetta.combinators :as c])
(:use [zetta.core :only [<$> <* *> <|> do-parser]]))
(ns blah
(:use [zetta.parser.seq :only (whitespace number char)]
[zetta.combinators :only (choice around)]
[zetta.core :only (*>, <*)])
(:require [zetta.core :as z]))
(def whitespaces (many whitespace))
(def id4
(around
;Hrm... I actually tried a similar approach before but:
(def identifier2
(around
whitespaces
(choice
[(*> (string "#")
(<* number (string "#")))
(*> (string "#")
(<* number (string "=")))])))
(def identifier
(around
whitespaces
(choice
[(<$> (partial apply vector)
(*> (string "#")
(<* number (string "#"))))
; ^ I think you should be using just number here right?
; you are trying to parse (many1 digit)
(<$> (partial apply vector)
(def identifier
(around
whitespaces
(choice
[(<$> (partial apply vector)
(*> (string "#")
(<* (many1 number) (string "#"))))
(<$> (partial apply vector)
(*> (string "#")
(<* (many1 number) (string "="))))])))