Skip to content

Instantly share code, notes, and snippets.

@gallais
gallais / Vector.ml
Last active June 11, 2025 16:36
Length-indexed lists
(*
We don't really care about the data constructors here
but they are needed, cf:
https://sympa.inria.fr/sympa/arc/caml-list/2013-10/msg00190.html
*)
type zero = Zero
type 'a succ = Succ
(*
[] has length 0

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
@mandubian
mandubian / gist:0fd090c0f75a46346f5e7898eeac9e28
Last active September 15, 2017 15:11
Improving compile-time for structure based on implicits resolutions
@milessabin
milessabin / dec.scala
Created March 21, 2016 10:31
Idris's Dec in Scala
sealed trait Dec[+T]
final case class Yes[T](t: T) extends Dec[T]
final case object No extends Dec[Nothing]
object Dec extends Dec0 {
implicit def yes[T](implicit t: T): Dec[T] = Yes(t)
}
trait Dec0 {
implicit def no[T]: Dec[T] = No
@bishboria
bishboria / springer-free-maths-books.md
Last active April 19, 2026 15:50
Springer made a bunch of books available for free, these were the direct links
@lihaoyi
lihaoyi / trace.scala
Last active December 27, 2015 19:32
Downloading JSON and splatting it into some files in 4 lines of Scala with Ammonite http://lihaoyi.github.io/Ammonite/
haoyi-mbp:Ammonite haoyi$ ~/amm
Loading...
Welcome to the Ammonite Repl 0.5.2
(Scala 2.11.7 Java 1.8.0_25)
haoyi-Ammonite@ load.ivy("org.scalaj" %% "scalaj-http" % "2.2.0")
haoyi-Ammonite@ import ammonite.ops._, scalaj.http._
import ammonite.ops._, scalaj.http._
haoyi-Ammonite@ Http("https://api.github.com/repos/scala/scala").asString
res2: HttpResponse[String] = HttpResponse(
+-----------------------------------------------------------------------------------------------------+
| name | bits | bytes | min | actual min value | max | actual max value |
|---------+--------+--------+-------+----------------------------+--------+---------------------------|
| boolean | 1-bit | -- | false | | true | |
| byte | 8-bit | 1-byte | -2^7 | -128 | 2^7-1 | 127 |
| short | 16-bit | 2-byte | -2^15 | -32'768 | 2^15-1 | 32'767 |
| char | 16-bit | 2-byte | 0 | '\u0000' | 2^16-1 | '\uffff' (65535) |
| int | 32-bit | 4-byte | -2^31 | -2'147'483'648 | 2^31-1 | 2'147'483'647 |
| long | 64-bit | 8-byte | -2^63 | -9'223'372'036'854'775'808 | 2^63-1 | 9'223'372'036'854'775'807 |
| float | 32-bit | 4-byte | +/- -3.4028235 * 10^38 | +/- 3.4028235 * 10^38
@chambart
chambart / packed_fields_gadt.ml
Last active April 3, 2023 02:00
Packed fields in integers
type zero = unit
type 'a succ = unit -> 'a
type one = zero succ
type 'a plus_1 = 'a succ
type 'a plus_2 = 'a plus_1 plus_1
type 'a plus_4 = 'a plus_2 plus_2
type 'a plus_8 = 'a plus_4 plus_4
@paulp
paulp / kMDItemWhereFroms.sh
Created May 9, 2015 17:19
Exploit extended file attributes to figure out where some downloads came from.
#!/usr/bin/env bash
#
for file in "$@"; do
attr="$(xattr -p com.apple.metadata:kMDItemWhereFroms "$file" 2>/dev/null)"
url () {
echo "$attr" | xxd -r -p | plutil -convert xml1 -o - - | \
ack --output='$1' '(?:<string>)(.+?)</string>' | head -n1
}
@chandu0101
chandu0101 / CssPager.scala
Last active November 10, 2015 15:22
ReactPager using scalacss
object CssPager {
type CLICKEVENT = Int => Unit
object Style extends StyleSheet.Inline {
import dsl._
val pager = style(margin(20.px),
unsafeChild(".previous")(float.left),
unsafeChild(".next")(float.right)
)