Skip to content

Instantly share code, notes, and snippets.

View DonaldKellett's full-sized avatar

Donald Sebastian Leung DonaldKellett

View GitHub Profile
@DonaldKellett
DonaldKellett / RecordPuns.purs
Created January 2, 2019 10:05
PureScript by Example - 5.14 Record Puns - Exercise 1-3 Solutions
module RecordPuns where
import Prelude
import Data.Maybe
-- Utilities provided in 5.12 Algebraic Data Types of PureScript by Example
data Shape
= Circle Point Number
| Rectangle Point Number Number
| Line Point Point
@DonaldKellett
DonaldKellett / PictureExtended.purs
Created January 2, 2019 11:25
PureScript by Example - 5.17 Computing Bounding Rectangles - Exercise 1-2 Solutions
module PictureExtended where
-- Based on and extended from the project setup of 5. Pattern Matching
-- of PureScript by Example:
-- https://github.com/paf31/purescript-book/blob/master/exercises/chapter5/src/Data/Picture.purs
import Prelude
import Data.Foldable (foldl)
import Global as Global
@DonaldKellett
DonaldKellett / ShowMe.purs
Created January 2, 2019 13:53
PureScript by Example - 6.3 Show Me! - Exercise 1 Solution
module ShowMe where
import Prelude
-- Utilities from https://github.com/paf31/purescript-book/blob/master/exercises/chapter5/src/Data/Picture.purs
-- required to complete this exercise
data Point = Point
{ x :: Number
, y :: Number
@DonaldKellett
DonaldKellett / CommonTypeClasses.purs
Created January 2, 2019 14:30
PureScript by Example - 6.4 Common Type Classes - Exercise 1 Solution
module CommonTypeClasses where
import Prelude
-- Boilerplate code
newtype Complex = Complex
{ real :: Number
, imaginary :: Number
}
@DonaldKellett
DonaldKellett / InstanceDependencies.purs
Created January 2, 2019 15:57
PureScript by Example - 6.7 Instance Dependencies - Exercise 1-6 Solutions
module InstanceDependencies where
import Prelude
import Data.Array
import Data.Foldable
-- Boilerplate for Exercises 1-3, 5
data NonEmpty a = NonEmpty a (Array a)
-- For easier debugging
@DonaldKellett
DonaldKellett / Superclasses.purs
Created January 3, 2019 09:03
PureScript by Example - 6.11 Superclasses - Exercise 1-4 Solutions
module Superclasses where
import Prelude
import Data.Array
import Data.Foldable
import Data.Maybe
-- Exercise 1
maxOf :: Partial => Array Int -> Int
maxOf = fromJust <<< maximum
@DonaldKellett
DonaldKellett / Hashable.purs
Created January 3, 2019 09:44
PureScript by Example - 6.12 A Type Class for Hashes - Exercise 2-3 Solutions
module Hashable
( HashCode
, hashCode
, class Hashable
, hash
, hashEqual
, combineHashes
) where
-- Supplementary module for MoreHashables.purs
@DonaldKellett
DonaldKellett / Proof.md
Created January 5, 2019 14:19
PureScript by Example - 8.7 Monads and Applicatives - Exercise 6 Solution (Written Exercise)

Theorem

In PureScript, the expression:

lift2 f (pure a) (pure b)

is equivalent to:

@DonaldKellett
DonaldKellett / B4B_smarter.v
Created October 31, 2019 15:19
A formal proof that @Blind4Basics is getting smarter every day
(*
* A formal proof that @Blind4Basics is getting smarter every day
* Special thanks to @AwelEshetu for raising this question and
* @Steffan153 for challenging me into making this compile ;-)
*)
Definition Blind4Basics (_ _ _ _ _ : unit) := True.
Definition is := tt.
Definition getting := tt.
@DonaldKellett
DonaldKellett / q1.js
Created November 24, 2019 08:45
HKUST COMP 3711H Fall 2019-20 Written Assignment #4 - Q1 Solution
/*
* q1.js
* Script used to complete COMP 3711H Fall 2019-20 Written Assignemtn #4 Question 1
* If you used this script in your assignment then you MUST make attribution to it!
* Author: @DonaldKellett (LEUNG, Donald Sebastian)
*/
// Original weight matrix W
let wMatrix = [
[0, 8, 10, Infinity, 3, Infinity],