Skip to content

Instantly share code, notes, and snippets.

View akhileshs's full-sized avatar

Akhilesh Srikanth akhileshs

  • San Francisco, CA
View GitHub Profile
@pchiusano
pchiusano / traverse.scala
Created March 23, 2017 15:02
Another encoding of `Traverse` in terms of `mapAccumulate`
/**
* In this version of `Traverse`, sequencing always goes through `List` (or some other canonical sequence type),
* which can be done in a stack-safe manner using a balanced fold as in https://gist.github.com/pchiusano/7667597.
* It's quite nice that `sequence` and `traverse` are now derived functions.
*/
trait Traverse[F[_]] extends Functor[F] {
/** Inefficient but correct implementation of `toList` in terms of `mapAccumulate`. */
def toList[A](f: F[A]): List[A] = mapAccumulate(f, List())((a, rbuf) => (a, a :: rbuf))._2.reverse
/** The only function that must be implemented. Must be consistent with `map`. */
@reborg
reborg / rich-already-answered-that.md
Last active May 8, 2024 14:20
A curated collection of answers that Rich gave throughout the history of Clojure

Rich Already Answered That!

A list of commonly asked questions, design decisions, reasons why Clojure is the way it is as they were answered directly by Rich (even when from many years ago, those answers are pretty much valid today!). Feel free to point friends and colleagues here next time they ask (again). Answers are pasted verbatim (I've made small adjustments for readibility, but never changed a sentence) from mailing lists, articles, chats.

How to use:

  • The link in the table of content jumps at the copy of the answer on this page.
  • The link on the answer itself points back at the original post.

Table of Content

assume: () -> a
True -> a
not True \/ a
False \/ a
a \/ False
not a -> False
(a -> False) -> False
True = ()
@paulp
paulp / global.sbt
Last active October 16, 2018 19:09
continuous compilation of the sbt build
// These lines go in ~/.sbt/0.13/global.sbt
watchSources ++= (
(baseDirectory.value * "*.sbt").get
++ (baseDirectory.value / "project" * "*.scala").get
++ (baseDirectory.value / "project" * "*.sbt").get
)
addCommandAlias("rtu", "; reload ; test:update")
addCommandAlias("rtc", "; reload ; test:compile")
addCommandAlias("ru", "; reload ; update")
@Dierk
Dierk / Main.purs
Created November 14, 2016 20:11
Monoidal Fizzbuzz in Purescript
module Main where
import Control.Monad.Eff.Console (log)
import Data.List.Lazy (take, zipWith, fromFoldable, cycle, iterate, foldr)
import Data.Monoid (mempty, (<>))
import Data.Maybe (Maybe(..), fromMaybe)
import Prelude ( show, map, ($), (+))
main = do
@madsbuch
madsbuch / Proof.hs
Last active January 12, 2023 18:31
{-# LANGUAGE GADTs #-} -- Soft dependent types
{-# LANGUAGE PolyKinds #-} -- Allow general specification of Refl
{-# LANGUAGE RankNTypes #-} -- Explicit quantification and inline type context
{-# LANGUAGE DataKinds #-} -- Lift data constructors to Kind level
{-# LANGUAGE TypeFamilies #-} -- Equational reasoning about types
{-# LANGUAGE TypeOperators #-} -- Allow types such as :~:
-- Starting the interactive shell:
--
-- ghci -XDataKinds -XTypeOperators -Wall -Werror Script.hs

nkpart: Why haskell? Super cheap upgrades. Major compiler versions, major library versions, no worries.

parqit: @nkpart can you please elaborate on "cheap"?

For sure!

At veitchlister.com.au, we use a mix of Haskell and Ruby (with a smattering of Java and C++ around as well). As you can imagine, there are stark difference when you are maintaining code across these ecosystems! We have been doing this for a few years now, such that we have code in all languages that has been around for at least a few years, and we've been through large refactors, system upgrades and dependency upgrades in each.

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@Rich-Harris
Rich-Harris / footgun.md
Last active May 6, 2024 10:24
Top-level `await` is a footgun

Edit — February 2019

This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:

  • TC39 is currently moving forward with a slightly different version of TLA, referred to as 'variant B', in which a module with TLA doesn't block sibling execution. This vastly reduces the danger of parallelizable work happening in serial and thereby delaying startup, which was the concern that motivated me to write this gist
  • In the wild, we're seeing (async main(){...}()) as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problems
  • Therefore, a version of TLA that solves the original issue is a valuable addition to the language, and I'm in full support of the current proposal, which you can read here.

I'll leave the rest of this document unedited, for archaeological

@tonymorris
tonymorris / EggsToast.java
Created August 29, 2016 12:46
What is the output of this program?
// What is the output of this program?
// a) x = 2
// b) x = 3
// c) compile-error
// d) runtime exception
// e) something else _____
abstract class Eggs {
abstract void m();
Eggs() {