Skip to content

Instantly share code, notes, and snippets.

View prisms.hs
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
data These a b =
This a
| That b
| Both a b
deriving (Eq, Show)
View blah.hs
{-# LANGUAGE LambdaCase #-}
import Control.Lens
data Blah a =
Blah1 a
| Blah2 a
| BlahS String
deriving (Eq, Show)
// >>> given([notnull 1,null,notnull 3])
// null
// >>> given([notnull 1,notnull 2,notnull 3])
// notnull [1,2,3]
given(list) {
var r = List.empty
for(var i = 0; i < list.length; i++) {
if(list[i] == null)
return null
View docker
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y libreoffice imagemagick ghostscript rsync bash pdftk texlive-xetex texlive-luatex ttf-dejavu sudo zlib1g-dev ghc cabal-install
RUN export TZ=Australia/Brisbane
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN export LANG=C.UTF-8
RUN grep write /etc/ImageMagick-6/policy.xml
View Optics
View whichismorereadable.scala
// Which of f or g are more readable, and if possible, why?
def f(x: Seq[Int]): Int =
x.toList match {
case Nil => 99
case lst => lst.sum
def g(x: Seq[Int]): Int =
x.toList match {
View nonoverlapping_patterns.hs
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
import Data.Bool
data DataTypeWithMillionsOfConstructors =
| DataTypeWithMillionsOfConstructors1
| DataTypeWithMillionsOfConstructors2
View ListZipper.scala
case class ListZipper[A](lefts: List[A], focus: A, rights: List[A]) {
def map[B](f: A => B): ListZipper[B] =
ListZipper(lefts map f, f(focus), rights map f)
def ap[B](f: ListZipper[A => B]): ListZipper[B] =
ListZipper( { case (ff, aa) => ff(aa) }
, f.focus(focus)
, { case (ff, aa) => ff(aa) }
View FlightPlanv1.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsd:schema xmlns:xsd="" xmlns="" xmlns:fp="" targetNamespace="" elementFormDefault="qualified">
To transform a FlightPlan v1 XML document to GPX format a stylesheet will exist
on the Garmin website.
<xsd:element name="flight-plan" type="FlightPlan_t">
<xsd:key name="WaypointIdKey">
View ZeroOrTwo.hs
data ZeroOrTwo a =
| Two a a
instance Functor ZeroOrTwo where
fmap _ Zero =
fmap f (Two a1 a2) =
Two (f a1) (f a2)