- Read a table of data from disk
Cassava: exploratory CSV parsing
#!/usr/bin/env python | |
""" | |
Tail-Recursion helper in Python. | |
Inspired by the trampoline function at | |
http://jasonmbaker.com/tail-recursion-in-python-using-pysistence | |
Tail-recursive functions return calls to tail-recursive functions | |
(themselves, most of the time). For example, this is tail-recursive: |
#!/usr/bin/env python | |
""" | |
Translated from the example in | |
Deprecating the Observer Pattern (Maier, Rompf, Odersky) | |
http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf | |
Their Scala example: | |
Reactor.once { self => | |
// step 1: |
#!/usr/bin/env runhaskell | |
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, TypeSynonymInstances, FunctionalDependencies #-} | |
{- Monad-like trees can do cool things like factoring integers and | |
- pruning leaves with bind (>>=). | |
- | |
- Internal nodes are annotated with a measure of some sort that can be used | |
- for efficient indexing and sizing. | |
- | |
- Measured typeclass and tagged nodes from |
#!/usr/bin/env runhaskell | |
{- Project Euler 96 - Solve Sudoku! | |
- | |
- Compile it with ghc -o blah --make sudoku | |
- | |
- And grab sudoku.txt from | |
- http://projecteuler.net/index.php?section=problems&id=96 | |
- | |
- Answer: 24702 |
package object tasks { | |
trait Task[A, B] { | |
private[tasks] def run(): Either[A, B] | |
def map[C](f: B => C): Task[A, C] = ??? | |
def flatMap[C](f: B => Task[A, C]): Task[A, C] = ??? | |
} | |
private[tasks] class Http[A, B]( | |
data: HttpRequest, | |
handler: Either[Throwable, HttpResponse] => Either[A, B], |
import scala.languageFeature.higherKinds | |
import cats.{Applicative, Id, ~>} | |
object Shapes { | |
case class Child[F[_]](nickname: F[String], age: F[Int]) | |
case class Adult[F[_]](job: F[String], innerChild: Child[F]) | |
class ApplicativeTrans[F[_]](implicit applicativeF: Applicative[F]) extends ~>[Id, F] { | |
override def apply[A](value: A): F[A] = applicativeF.pure(value) |
package example | |
import cats.~> | |
import org.scalatest.FunSuite | |
object CopSpec { | |
final case class Foo[+A](value: A) | |
final case class Bar[+A](value: A) | |
final case class Baz[+A](value: A) |
#!/usr/bin/env stack | |
-- stack --resolver lts-13.9 --install-ghc runghc --package aeson --package tasty --package text | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE DerivingVia #-} | |
{-# LANGUAGE DuplicateRecordFields #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
import Data.Aeson |
#!/usr/bin/env stack | |
-- stack --resolver lts-13.9 --install-ghc runghc --package aeson --package tasty --package text | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE DerivingVia #-} | |
{-# LANGUAGE DuplicateRecordFields #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
{-# LANGUAGE UndecidableInstances #-} |