Skip to content

Instantly share code, notes, and snippets.

View malzzz's full-sized avatar

Mallory M. malzzz

  • Bivalent Capital
  • /dev/null
View GitHub Profile
@rzeigler
rzeigler / TerminalIO.hs
Last active September 12, 2016 17:40
Translation of https://github.com/tpolecat/examples/blob/master/src/main/scala/eg/FreeMonad.scala FreeMonad example to Haskell as well as an example program.
import Control.Monad.Free
import Control.Monad.State.Lazy
data TerminalOp a = ReadLine (String -> a) | WriteLine String a
instance Functor TerminalOp where
fmap f (ReadLine g) = ReadLine (f . g)
fmap f (WriteLine s a) = WriteLine s (f a)
type TerminalIO a = Free TerminalOp a
@matlux
matlux / simple-clojure-scala-interop.scala
Last active January 23, 2017 11:35
Clojure and Scala are both amazing functional languages that have a lot in common. For example their immutable data structures. Both have some amazing libraries. Why not being able to call one from the other? This is a simple Clojure in Scala interop. This is an example showing how to call Clojure function within Scala using standard Scala data …
sealed trait EdnExpr {
def value : Expr
def mdata : Map[Expr,Expr]
override def equals(other : Any) = other match {
case that : EdnExpr => this.value == that.value
case _ => false
}
}
type Expr = Any
@gauthamnair
gauthamnair / gist:cacd07b3b0f1a4ff72d0
Created July 11, 2015 20:42
transducers tic-tac
//--
// Clojure's Transducers
// (the simpler parts)
//--
// References:
@7shi
7shi / qsort.hs
Last active September 12, 2016 17:33
[Scala][Haskell]quicksort
qsort [] = []
qsort (n:xs) = qsort lt ++ [n] ++ qsort gteq where
lt = [x | x <- xs, x < n]
gteq = [x | x <- xs, x >= n]
@jkeefe
jkeefe / raspberry-pi-ble-sniffer.md
Last active September 16, 2023 14:33
Notes on using Adafruit's "Bluefruit" BLE sniffer with a Raspberry Pi

BLUETOOTH SNIFFER

Working to sniff Bluetooth Low Energy with the adafruit sniffer

For more information, see this blog post

Going the python route, as described here

before installing pySerial, did ...

@odersky
odersky / A simpler way to returning the "current" type in Scala.
Last active April 5, 2024 13:34
A simpler way to returning the "current" type in Scala.
/** This is in reference to @tploecat's blog http://tpolecat.github.io/2015/04/29/f-bounds.html
* where he compares F-bounded polymorphism and type classes for implementing "MyType".
*
* Curiously, the in my mind obvious solution is missing: Use abstract types.
*
* A lot of this material, including an argument against F-bounded for the use-case
* is discussed in:
*
* Kim B. Bruce, Martin Odersky, Philip Wadler:
* A Statically Safe Alternative to Virtual Types. ECOOP 1998: 523-549
object TransducerSpecs extends Specification with ScalaCheck {
import Process._
import StreamUtils._
"effectful stream transducers" should {
def id[I]: Transducer[Nothing, I, I] =
transducer.receive1[Nothing, I, I](emit).repeat
"perform a simple identity transformation" in prop { xs: List[List[Int]] =>
val p = emitAll(xs map emitAll).toSource.join
@non
non / transducers2.scala
Created January 25, 2015 16:52
Basic encoding of Transducers with a little fanciness
import spire.algebra._
import spire.implicits._
object Transducer {
type RF[R, A] = (R, A) => R
def apply[A, B](f: A => B) =
new Transducer[B, A] {
def apply[R](rf: RF[R, B]): RF[R, A] = (r, a) => rf(r, f(a))
}
@tonymorris
tonymorris / Tree.scala
Created January 22, 2015 03:55
Rose-tree in Scala, demonstrating comonad implementation
case class Tree[A](root: A, forest: List[Tree[A]]) {
def map[B](f: A => B): Tree[B] =
coflatMap(t => f(t.copoint))
// categorical dual to canonical "flatMap"
def coflatMap[B](f: Tree[A] => B): Tree[B] = {
import Tree.unfoldTree
unfoldTree(this, (a: Tree[A]) => (f(a), a.forest))
}
@jhrr
jhrr / monads.txt
Created January 13, 2015 16:39
"Programming with Effects" by Graham Hutton -- http://www.cs.nott.ac.uk/~gmh/monads
PROGRAMMING WITH EFFECTS
Graham Hutton, January 2015
Shall we be pure or impure?
The functional programming community divides into two camps:
o "Pure" languages, such as Haskell, are based directly
upon the mathematical notion of a function as a
mapping from arguments to results.