This file contains 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
+------+----------------------------+ | |
| ^ | | |
| | | depth: 12.75" | |
| | 12.92" | | |
| | | | |
| v | | |
+------+----------------------------+ | |
| | | |
| | | |
| | |
This file contains 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 scala.annotation.tailrec | |
/** | |
* A Type-aligned list is a list of functions which can be | |
* chained together. They are "type-aligned" because their | |
* types all line. For example, suppose you have the following | |
* functions: | |
* | |
* val foo: Int => String = i => i.toString | |
* val bar: String => Char = s => s.head |
This file contains 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
package cats | |
import cats.data.{StateT, WriterT} | |
import cats.implicits._ | |
/** | |
* TypeLevel is working on some alternative encodings of the Monad Transformer | |
* Library (MTL). The existing solution in cats was broken for a few reasons. | |
* One annoying issue made it imposisible to use for-comprehension with more | |
* than one Monad$FOO constraint owing to implicit resolution ambiguities. |
This file contains 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
// https://github.com/mpilquist/simulacrum | |
trait FlatMap[F[_]] extends Apply[F] with _root_.scala.Serializable { | |
def flatMap[A, B](fa: F[A])(f: _root_.scala.Function1[A, F[B]]): F[B]; | |
def >>=[A, B](fa: F[A])(f: _root_.scala.Function1[A, F[B]]): F[B] = flatMap(fa)(f); | |
def flatten[A](ffa: F[F[A]]): F[A] = flatMap(ffa)(((fa) => fa)); | |
def followedBy[A, B](fa: F[A])(fb: F[B]): F[B] = flatMap(fa)(((x$1) => fb)); | |
@inline final def >>[A, B](fa: F[A])(fb: F[B]): F[B] = followedBy(fa)(fb); | |
def followedByEval[A, B](fa: F[A])(fb: Eval[F[B]]): F[B] = flatMap(fa)(((x$2) => fb.value)); | |
override def ap[A, B](ff: F[_root_.scala.Function1[A, B]])(fa: F[A]): F[B] = flatMap(ff)(((f) => map(fa)(f))); |
This file contains 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 scala.annotation.tailrec | |
import scala.language.higherKinds | |
object jazz { | |
trait Functor[F[_]] { | |
def fmap[A,B](value: F[A])(func: A => B): F[B] | |
} | |
abstract class Applicative[F[_]](val functor: Functor[F]) extends Functor[F] { |
This file contains 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
☭ scala foo.scala | |
cat: /release: No such file or directory | |
java.lang.NullPointerException | |
at Main$Monad.<init>(foo.scala:29) | |
at Main$$anon$1.<init>(foo.scala:58) | |
at Main$.<init>(foo.scala:58) | |
at Main$.<clinit>(foo.scala) | |
at Main.main(foo.scala) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) |
This file contains 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
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Network.Wai (pathInfo, Request, requestMethod, Response, responseLBS, ResponseReceived) | |
import Network.Wai.Handler.Warp (run) | |
import Network.HTTP.Types (status200, status401) | |
-- note: type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived | |
application :: Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived |
This file contains 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
-- Our goal is to create a type describing a list of events. This is our | |
-- type-level DSL. | |
-- We will then use typeclass resolution to "interpret" this type-level DSL | |
-- into two things: | |
-- 1. A comma-separated list of events | |
-- 2. A method that, when given an event name and a payload, will try to parse | |
-- that event type with the payload. A form of dynamic dispatching | |
-- | |
-- To model a list of types we will use tuples. You can imagine the list of | |
-- types "Int, String, Char" to look like: |
This file contains 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
(* 99 problems in OCaml: https://ocaml.org/learn/tutorials/99problems.html *) |
This file contains 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
object cps { | |
/** | |
* | |
* The code below translates this blog post | |
* http://blog.infinitenegativeutility.com/2016/8/resources--laziness--and-continuation-passing-style) | |
* into scala, and uses laziness where appropriate to highlight the issue. | |
* | |
* I also include a type for IO. This is mainly illustrative, but also ensures | |
* we "sequence" actions appropriately. Haskell's IO monad works in tandem with the |
NewerOlder