Skip to content

Instantly share code, notes, and snippets.

View crispywalrus's full-sized avatar

chris vale crispywalrus

View GitHub Profile
https://floooh.github.io/2018/06/17/handles-vs-pointers.html
;;; ob-scala.el --- org-babel functions for Scala evaluation
;; Copyright (C) 2012 Free Software Foundation, Inc.
;; Author: Andrzej Lichnerowicz
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; This file is part of GNU Emacs.
package foo
import zio._
object Foo extends App {
object ModuleA {
type A = Has[ServiceA]
trait ServiceA {
@crispywalrus
crispywalrus / coroutine.ml
Created June 27, 2019 19:57 — forked from keigoi/coroutine.ml
Coroutine implementation in OCaml, with Oleg's delimited continuation. see http://okmij.org/ftp/continuations/implementations.html#caml-shift
(* Coroutine implementation in OCaml, with Oleg's delimited continuation *)
(* see http://okmij.org/ftp/continuations/implementations.html#caml-shift *)
module D = Delimcc
(* Coroutine yielded a value of type 'a, and will resume with some value of type 'b *)
type ('a, 'b) suspend =
| Cont of 'a * ('b, ('a,'b) suspend) D.subcont
| Finish
let start_coroutine f =
@crispywalrus
crispywalrus / gen.ml
Created June 27, 2019 16:59 — forked from mariusae/gen.ml
python generators in ocaml using delimcc
type ('a, 'b) t = Done | More of 'a * ('b -> ('a, 'b) t)
let gen f =
(*
* Note: the first value to yield gets thrown away as the generator
* has not yet started.
*)
let start _ =
let p = Delimcc.new_prompt () in
Delimcc.push_prompt p begin fun () ->
@crispywalrus
crispywalrus / Test.scala
Created June 7, 2019 05:15 — forked from SystemFw/Test.scala
Recursively increment every Int in a case class by a given runtime quantity
object Test {
import inc._
case class Foo(i: Int, s: String)
case class Bar(f: Int, a: Foo, n: Int)
val res = Bar(0, Foo(1, "hello"), 2).incBy(2)
//res0: Test.Bar = Bar(2,Foo(3,hello),4)
}
@crispywalrus
crispywalrus / Lib.scala
Created June 7, 2019 05:15 — forked from SystemFw/Lib.scala
Shapeless: derive JDBC Results for arbitrary case classes
import shapeless._ // requires.shapeless
import cats._, implicits._, data.Kleisli // requires.cats
import cats.sequence._ //requires kittens
import cats.effect.IO //requires cats-effect
// ofc, uses "-Ypartial-unification" and kind-projector
case class Result() // replace with the JDBC equivalent
case class DB(val r: Result) {
def nextInt: IO[Int] = ??? //IO(g.nextInt)
@crispywalrus
crispywalrus / Test.scala
Created June 7, 2019 05:15 — forked from SystemFw/Test.scala
Shapeless: Convert between any two compatible case classes, selecting a subset of the fields
object Test {
case class User(name: String, age: Int)
case class UserDTO(name: Option[String], age: Option[Int])
import conversions._
def a = User("John", 24).convertTo[UserDTO](Set("name"))
// res0: Test.UserDTO = UserDTO(Some(John),None)
case class WrongFieldNames(surname: Option[String], age: Option[Int])
@crispywalrus
crispywalrus / PolyWithArgs.scala
Created June 7, 2019 05:14 — forked from SystemFw/PolyWithArgs.scala
Shapeless Poly with explicit arguments
object Args {
// it requires the cats, shapeless, and kittens libraries
import cats._, implicits._
import cats.sequence._
import shapeless._, labelled._
import shapeless.syntax.singleton._
// Gitter question:
// it masks fields of a record according to an explicit argument
@crispywalrus
crispywalrus / dune
Created May 2, 2019 15:29
A solution for rosettacode knapsack in ocaml
(executable
(name knapsack))