This file contains hidden or 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
// This gist contains the JavaScript version of the code from the blog post | |
// https://hurryabit.github.io/blog/stack-safety-for-free/ | |
function triangular(n) { | |
if (n == 0) { | |
return 0; | |
} else { | |
return n + triangular(n - 1); | |
} | |
} |
This file contains hidden or 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
# This gist contains the Python version of the code from the blog post | |
# https://hurryabit.github.io/blog/stack-safety-for-free/ | |
import sys | |
from typing import Callable, Generator, TypeVar | |
Arg = TypeVar("Arg") | |
Res = TypeVar("Res") | |
def triangular(n: int) -> int: |
This file contains hidden or 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
// This gist contains the code from the blog post | |
// https://hurryabit.github.io/blog/stack-safety-for-free/ | |
// We need Rust nightly to run the code. | |
#![feature(generators, generator_trait)] | |
use std::ops::{Generator, GeneratorState}; | |
use std::pin::Pin; | |
fn triangular(n: u64) -> u64 { | |
if n == 0 { | |
0 |
This file contains hidden or 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
import sys | |
def recurse(f): | |
""" | |
Decorator that turns a "yield transformed" recursive function into a | |
function that computes the same value as the actual recursive function but | |
does not blow the stack, even for large inputs. The "yield transformed" | |
version of a recursive function `f(x)` is obtained by replacing all | |
recursive calls `f(x')` into `(yield x')`. |
This file contains hidden or 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
#!/usr/bin/env node | |
"use strict"; | |
const fs = require("fs"); | |
const SPEEDSCOPE_JSON_SCHEMA = "https://www.speedscope.app/file-format-schema.json"; | |
const [node, prog, ...options] = process.argv; | |
if (options[options.length - 2] !== "-o") { |
This file contains hidden or 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
let nil = { isEmpty = true } in | |
let cons = fun hd tl -> { isEmpty = false; head = hd; tail = tl } in | |
let rec foldrList = fun f z xs -> | |
if xs.isEmpty then | |
z | |
else | |
f xs.head (foldrList f z xs.tail) | |
in | |
let rec foldlList = fun f z xs -> | |
if xs.isEmpty then |
This file contains hidden or 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
daml 1.2 | |
module BikeShop where | |
import DA.Date | |
import DA.Time | |
template Template t => Proposal t with | |
proposer: Party | |
receiver: Party |
This file contains hidden or 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
-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | |
-- SPDX-License-Identifier: Apache-2.0 | |
daml 1.2 | |
module PaintHouse where | |
template PaintHouse with | |
owner : Party | |
painter : Party | |
cleaner : Party |
This file contains hidden or 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
-- Copyright (c) 2019, Digital Asset (Switzerland) GmbH and/or its affiliates. | |
-- All rights reserved. | |
daml 1.2 | |
module Celebration where | |
import DA.Date qualified as Date | |
import DA.List | |
template Celebration with |