The following are appendices from Optics By Example, a comprehensive guide to optics from beginner to advanced! If you like the content below, there's plenty more where that came from; pick up the book!
This file contains hidden or 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
{-# OPTIONS_GHC -Wall #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
import Control.Lens | |
data These a b = | |
This a | |
| That b | |
| Both a b | |
deriving (Eq, Show) |
This file contains hidden or 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 LambdaCase #-} | |
import Control.Lens | |
data Blah a = | |
Blah1 a | |
| Blah2 a | |
| BlahS String | |
deriving (Eq, Show) |
This file contains hidden or 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
// >>> 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 | |
else |
This file contains hidden or 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
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 |
This file contains hidden or 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
// 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 { |
This file contains hidden or 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
{-# OPTIONS_GHC -Wall #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
import Control.Lens | |
import Data.Bool | |
data DataTypeWithMillionsOfConstructors = | |
DataTypeWithMillionsOfConstructors0 | |
| DataTypeWithMillionsOfConstructors1 | |
| DataTypeWithMillionsOfConstructors2 |
This file contains hidden or 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
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( | |
f.lefts.zip(lefts).map { case (ff, aa) => ff(aa) } | |
, f.focus(focus) | |
, f.rights.zip(rights).map { case (ff, aa) => ff(aa) } | |
) |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www8.garmin.com/xmlschemas/FlightPlan/v1" xmlns:fp="http://www8.garmin.com/xmlschemas/FlightPlan/v1" targetNamespace="http://www8.garmin.com/xmlschemas/FlightPlan/v1" elementFormDefault="qualified"> | |
<xsd:annotation> | |
<xsd:documentation> | |
To transform a FlightPlan v1 XML document to GPX format a stylesheet will exist | |
on the Garmin website. | |
</xsd:documentation> | |
</xsd:annotation> | |
<xsd:element name="flight-plan" type="FlightPlan_t"> | |
<xsd:key name="WaypointIdKey"> |
This file contains hidden or 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
data ZeroOrTwo a = | |
Zero | |
| Two a a | |
instance Functor ZeroOrTwo where | |
fmap _ Zero = | |
Zero | |
fmap f (Two a1 a2) = | |
Two (f a1) (f a2) |