Skip to content

Instantly share code, notes, and snippets.

@gregberns
gregberns / the-algebra-of-algebraic-data-types.md
Created December 13, 2018 05:57
The Algebra of Algebraic Data Types, Part 1, by Chris Taylor
@gregberns
gregberns / SlowImplementationOfRights.purs
Created December 13, 2018 03:49
An implementation of the Either 'rights' function that is slow
import Data.Array (snoc)
import Data.Either (Either(..))
rights :: forall a b. Array (Either a b) -> Array b
rights array =
let
f (Left _) accumulator = accumulator
f (Right value) accumulator = snoc accumulator value
in
foldr f [] array
@gregberns
gregberns / FastImplementationOfRights.purs
Created December 13, 2018 03:49
A implementation of the Either 'rights' and 'lefts' functions
import Data.Either (Either(..), either, hush)
import Data.Array (mapMaybe)
import Data.Maybe (Maybe(..))
rights :: forall a b. Array (Either a b) -> Array b
rights array = mapMaybe hush array
-- Also the Lefts implementation
lefts :: forall a b. Array (Either a b) -> Array a
lefts array = mapMaybe (either Just (const Nothing)) array
@gregberns
gregberns / STMonadUse.purs
Created December 13, 2018 03:18
An example of the ST Monad to append items to a mutable array
import Data.Array
import Data.Array.ST (empty, push, freeze)
import Data.Either (Either(..))
import Control.Monad.ST.Internal (ST, foreach)
-- Return Rights from an Array of Either's using the ST monad
rights :: forall a b. Array (Either a b) -> Array b
rights array =
let
-- This seems to be required because
@gregberns
gregberns / ListToListOfLists.txt
Last active November 29, 2018 07:21
List a -> Int -> Int -> List (List a)
//How can we do this imperitive process with Haskell/Purescript style functions?
//Examples
// > generateQuestions([1,2,3,4,5,6,7,8])(3)(2)
// [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
// > generateQuestions([1,2,3,4,5])(2)(4)
// [ [ 1, 2 ], [ 3, 4 ], [ 5, 1 ], [ 2, 3 ] ]
@gregberns
gregberns / universe-css-getting-started.md
Last active November 20, 2018 16:03
Getting Started Guide to UniVerse MultiValue

UniVerse (CSS) - Getting Started

Get Connected

  1. Install Putty

  2. Connect to server over ssh

  3. Login with username then password

using System;
using System.Linq;
using System.Collections.Generic;
namespace DearCSharpYouLose {
public static class FuncExtension {
public static Func<A, C> Select<A, B, C>(this Func<A, B> f, Func<B, C> g) {
return a => g(f(a));
}
@gregberns
gregberns / haskell-course.hs
Created October 2, 2018 05:35
Intro Syntax for Haskell
{-# OPTIONS_GHC -fwarn-incomplete-patterns -Werror #-}
-- Show
-- p1 =
-- ...
-- method(f,f)
-- ...
-- p2 =
-- ...
@gregberns
gregberns / FunctionDeclaration.cs
Created September 17, 2018 15:35
C# Lambda Cheat Sheet
//Local Declaration
Func<string> returnsString = () => "";
Func<int, int> takesIntReturnsInt = i => i * 2;
//Class-Level Declaration
//Generic Params
@gregberns
gregberns / Cabal 2.2.0.0 Fails
Last active August 27, 2018 06:59
Cabal Install fails
Download `cabal-install-2.2.0.0-x86_64-apple-darwin-sierra.tar.gz`
Extract
Run:
Gregs-MacBook-Pro:downloads huck$ ./cabal --version
cabal-install version 2.2.0.0
compiled using version 2.2.0.1 of the Cabal library
Gregs-MacBook-Pro:downloads huck$ ./cabal install Cabal cabal-install
Warning: Parsing the index cache failed (Unknown encoding for constructor).
Trying to regenerate the index cache...