Skip to content

Instantly share code, notes, and snippets.

View jonschoning's full-sized avatar

Jon Schoning jonschoning

View GitHub Profile

The original code (~7.2s on my laptop).

import System.Random
import System.CPUTime

rainfall :: [Int] -> Int
rainfall xs = sum (zipWith (-) mins xs)
@jonschoning
jonschoning / four-solutions-to-a-trivial-problem.hs
Created August 8, 2017 14:36 — forked from Teggy/four-solutions-to-a-trivial-problem.hs
A Haskell "transcript" of Guy Steele's talk "Four Solutions to a Trivial Problem" (https://www.youtube.com/watch?v=ftcIcn8AmSY)
{-# LANGUAGE TypeSynonymInstances #-}
import Data.Monoid
import Data.Maybe
-- How much water does a "histogram" hold?
--
-- Inspired by Guy Steele's talk "Four Solutions to a Trivial Problem"
-- https://www.youtube.com/watch?v=ftcIcn8AmSY

What

A technique for writing parsers.

Why

  • Easy to understand
  • Generally applicable
  • Full power of the programming language at your disposal
  • Declarative
{-# LANGUAGE BangPatterns #-}
module Main where
import qualified Data.Text as Text
import Data.Text (Text, pack)
import Criterion.Main
import Test.QuickCheck.Arbitrary
import Test.QuickCheck
import Data.List
import qualified Data.Vector.Unboxed as U
@jonschoning
jonschoning / Liege.hs
Created June 18, 2017 18:59 — forked from mrkgnao/Liege.hs
Servant handled using free monads of coproducts of functors :)
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE ConstrainedClassMethods #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE DeriveFunctor, GADTs #-}
import Control.Monad.Writer
import Data.List (intercalate)
import Data.Foldable (traverse_)
data S m a where
It :: String -> m a -> S m a
Describe :: String -> S m a -> S m a
Group :: [S m a] -> S m a
BeforeEach :: m a -> S m (a -> b) -> S m b

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
#!/usr/bin/env stack
{-
stack
--resolver lts-8.4
--install-ghc
runghc
--package aeson
--package aeson-casing
--package base
--package bytestring
@jonschoning
jonschoning / oauth.hs
Created April 28, 2017 23:34 — forked from freckletonj/oauth.hs
Haskell Servant OAuth2.0 for GitHub
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
module Sand where
import Data.Aeson
@jonschoning
jonschoning / build.proj
Created April 19, 2017 16:41 — forked from dasMulli/build.proj
Sample CI build definition using MSBuild
<Project>
<ItemGroup>
<Solution Include="*.sln" />
<PublishProject Include="XXX.Mvc\XXX.Mvc.csproj" />
<TestProject Include="**\*.Test*.*proj" Exclude="XXX.Tests.Shared\XXX.Tests.Shared.csproj" />
</ItemGroup>
<Target Name="Build">
<MSBuild Projects="@(Solution)" Targets="Restore" ContinueOnError="ErrorAndStop" UnloadProjectsOnCompletion="true" UseResultsCache="false" />
<MSBuild Projects="@(PublishProject)" Targets="Publish" Properties="Configuration=Release" ContinueOnError="ErrorAndContinue" />