This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function balance { | |
['black', ['red', ['red', *, *, *], *, *], *, *] => 'balance-1', | |
['black', ['red', *, *, ['red', *, *, *]], *, *] => 'balance-2', | |
['black', *, *, ['red', ['red', *, *, *], *, *]] => 'balance-3', | |
['black', *, *, ['red', *, *, ['red', *, *, *]]] => 'balance-4', | |
* => 'balanced' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test1 { | |
Black(Red(Red(*, *, *), *, *), *, *) => 'balance-1', | |
Black(Red(*, *, Red(*, *, *)), *, *) => 'balance-2', | |
Black(*, *, Red(Red(*, *, *), *, *)) => 'balance-3', | |
Black(*, *, Red(*, *, Red(*, *, *))) => 'balance-4', | |
default => 'balanced' | |
} | |
function test2(tree) { | |
var res; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro to_str { | |
case { _ ($toks ...) } => { | |
return [makeValue(#{ $toks ... }.map(unwrapSyntax).join(''), #{ here })]; | |
} | |
} | |
to_str(1 2 3 4) | |
// '1234' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro protocol { | |
case { _ $name:ident { $fn:protocol_fn ... } } => { | |
// Probably not a good idea to rely on `__fresh`. Sweet.js should provide | |
// some sort of blessed gensym capability. | |
letstx $id = [makeValue(__fresh(), #{ here })]; | |
return #{ | |
function $name(proto, impl) { | |
if (!impl) { | |
impl = proto; | |
proto = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Control.Global (importLib) where | |
foreign import importLib | |
"function importLib(node) {\ | |
\ return function(global) {\ | |
\ if (typeof require !== 'undefined' && typeof process !== 'undefined') {\ | |
\ return require(node);\ | |
\ } else {\ | |
\ return window[global];\ | |
\ }\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test = map ((*) 2) >>> filter ((>) 15) >>> drop 3 >>> map show | |
src1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] | |
src2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
res1 = transduce' test src1 :: [String] | |
res2 = transduce' test src2 :: List String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro constexpr { | |
rule { ($e:expr) } => { | |
(function() { | |
macro cexpr { | |
case { _ } => { | |
return [makeValue($e, #{ here })]; | |
} | |
} | |
return cexpr; | |
}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arg |> foo[0].bar(42) | |
|> baz("hello", "there") | |
|> quux.foo().bar() | |
|> new Foo() | |
// Expands to: | |
// new Foo(quux.foo().bar(baz('hello', 'there', foo[0].bar(42, arg)))); | |
arg |> foo() |> bar | |
// SyntaxError: [|>] Expected function call | |
// 31: arg |> foo() |> bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Control.Monad.Eff (Eff) | |
import Data.List (List(..), (:)) | |
import Data.Maybe (Maybe(..)) | |
import Halogen (ParentState, parentState, ParentQuery, Component, parentComponent, ParentHTML, Natural, ParentDSL, HalogenEffects, runUI) | |
import Halogen.HTML as H | |
import Halogen.Util (runHalogenAff, awaitBody) | |
import Unsafe.Coerce (unsafeCoerce) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
class Thunked a | |
instance thunkedAll :: Thunked a | |
type Thunk b = forall a. Thunked a => b |