Skip to content

Instantly share code, notes, and snippets.

View Mercerenies's full-sized avatar

Silvio Mayolo Mercerenies

View GitHub Profile
@Mercerenies
Mercerenies / primes.hs
Created September 5, 2018 02:10
Count for the number of primes and semiprimes up to a given quantity
-- Haskell program which generates the table
import Data.Ratio
import Data.List
divides :: Integral a => a -> a -> Bool
divides y x = x `mod` y == 0
primeFactors :: Integral a => a -> [a]
primeFactors n | n < 1 = error "invalid input"
@Mercerenies
Mercerenies / assignment-profiling.lats
Last active June 11, 2018 21:20
Profiling of the various assignment-operator syntaxes in Latitude
;; manual
10000 times {
a := 1.
a= := { parent a := #'($1). }.
do { a = 2. }.
}.
;; assignable
import java.util.ArrayList;
import java.util.Collection;
public class CollRaw {
public static interface Test {
public StringBuilder append(Collection<?> value);
}
@Mercerenies
Mercerenies / nonemptytrans.hs
Created January 27, 2018 17:02
A monad transformer based on `NonEmptyT`
-- Note: The same warnings about ListT's poor behavior apply to this transformer.
-- https://wiki.haskell.org/ListT_done_right
import Data.List.NonEmpty
import Control.Monad
import Control.Monad.List
newtype NonEmptyT m a = NonEmptyT { unNonEmptyT :: m (NonEmpty a) }
@Mercerenies
Mercerenies / ziplist.agda
Created January 4, 2018 20:12
Proof of equivalence of two similar zip implementations
open import Agda.Builtin.Equality
record _∧_ (A B : Set) : Set where
constructor conj
field
proj₁ : A
proj₂ : B
data List (A : Set) : Set where