Skip to content

Instantly share code, notes, and snippets.

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 / 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

@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 / 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 / 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 / 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 / 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 / rust_ref-deref.md
Created December 29, 2018 18:24
Rust - ref/derefs explanation

Thanks to @user#0540 and @Globi#0117 on the #beginners discord

Question: Coming from JS/C#/Haskell and trying to understand the & and * a bit better. In this code snippet, the n in the lambda apparently can either be |&n| n%2==0 or |n| *n%2==0. Could some one explain this a bit better? I think its something to do with reference/defreferece, but still not comfortable with those ideas.

let arr: [u16; 5] = [1, 2, 3, 4, 5];
let mut iterator = arr.iter().filter(|&n| n%2==0);
interface Integer2Integer {
int apply(int n);
}
static int blah(Integer2Integer r) { return r.apply(99); }
class Plus10 : Integer2Integer { Integer2Integer { int apply(int n) { return n + 10; } }
Console.WriteLine(blah(new Plus())); // what does that print?
maybe even a type alias
type Integer2Integer = Int -> Int
blah r = r 99
@gregberns
gregberns / Lib.hs
Last active January 23, 2019 05:55
Attempt at running Hedgehog readme examples
module Lib
( someFunc
) where
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range