Skip to content

Instantly share code, notes, and snippets.

View skykanin's full-sized avatar

Nicholas skykanin

  • Norway
View GitHub Profile
@skykanin
skykanin / colour.bqn
Last active December 17, 2023 14:05
BQN syntax highlighting for Discord
# BQN syntax highlighting using ANSI for Discord
# functions
fsyms ← "+-×÷⋆√⌊⌈∧∨¬|≤<>≥=≠≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!𝕎𝕏𝔽𝔾𝕊"
# constants
csyms ← "·¯π∞" ∾ '0'+↕10
# 1-modifiers
omsyms ← "˙˜˘¨⌜⁼´˝`𝕣"
# 2-modifiers
tmsyms ← "∘○⊸⟜⌾⊘◶⎊⎉⚇⍟"
# special symbols
@skykanin
skykanin / MoleculeToAtoms.hs
Last active July 24, 2022 17:44
A parser for arbitrarily nested molecule groups.
{-# LANGUAGE LambdaCase #-}
module MoleculeToAtoms (parseMolecule) where
import Control.Applicative (Alternative (..), liftA2, optional)
import Control.Lens.Internal.Level (Deepening (runDeepening))
import Control.Monad ((>=>))
import Data.Char (isDigit, isLower, isUpper)
import Data.Either.Combinators (maybeToRight)
import Data.HashMap.Strict.InsOrd qualified as Map
@skykanin
skykanin / Eff.idr
Last active July 12, 2022 21:05
Extensible effects
||| An implementation of an extensible effect system based on freer monads
||| which leverages dependent types to enforce invariants in a type safe manner.
||| Sources:
||| - https://okmij.org/ftp/Haskell/extensible/more.pdf
||| - https://hackage.haskell.org/package/freer-simple-1.2.1.2
module Eff
%default total
||| A proof that the type constructor `f` is a member of the
@skykanin
skykanin / Comonad.hs
Created April 16, 2022 20:33
Grokking comonads
{-# LANGUAGE InstanceSigs #-}
module Comonad where
import Data.Map (Map)
import qualified Data.Map as M
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NE
@skykanin
skykanin / Continuations.idr
Last active February 11, 2022 15:26
Calculating Dependently-Typed Compilers
||| Calculating Dependently-Typed Compilers
||| Sources:
||| - https://dl.acm.org/doi/pdf/10.1145/3473587
||| - https://www.youtube.com/watch?v=4GkGNPXOmC8
||| - https://cs.nott.ac.uk/~psymp4/files/dependently-typed-compilers.zip
import Data.Nat
%default total
@skykanin
skykanin / Interact.hs
Created April 13, 2021 18:36
SDL abstraction code for myopia game
{- |
Module : Graphics.SDL.Internal.Interact
License : GNU GPL, version 3 or above
Maintainer : skykanin <3789764+skykanin@users.noreply.github.com>
Stability : alpha
Portability : portable
Module for the internal rendering loop logic
-}
module Graphics.SDL.Internal.Interact (interact) where
@skykanin
skykanin / Rings.hs
Last active March 18, 2021 18:05
Number typeclass hierarchy based on Ring theory
{-# LANGUAGE NoImplicitPrelude #-}
module Rings where
import Data.Bool ((||))
import Data.Int (Int)
import Data.Eq (Eq, (==))
import Data.Ord (Ord, (>=))
-- | For types that support an addition and multiplication operation
class Semiring a where
@skykanin
skykanin / Reverse.idr
Last active January 18, 2021 15:55
Proofs surrounding the list reverse function
import Data.Nat
import Prelude
%hide reverse
reverse : List a -> List a
reverse [] = []
reverse (x :: xs) = reverse xs ++ [x]
testRev1 : reverse (reverse [1, 2, 3]) = [1, 2, 3]
@skykanin
skykanin / playground.kt
Created December 16, 2020 14:30
playing around with functional kotlin
interface Semigroup<M> {
fun binary(a: M, b: M): M
}
interface Monoid<M>: Semigroup<M> {
val neutral: M
}
fun <A, M> foldMap(m: Monoid<M>, f: (A) -> M, list: List<A>): M =
list.map(f).fold(m.neutral, m::binary)
@skykanin
skykanin / playground.ts
Created December 16, 2020 14:30
playing around with functional typescript
interface Semigroup<A> {
binary: (a: A, b: A) => A
}
interface Monoid<A> extends Semigroup<A> {
neutral: A
}
function foldMap<A, M>(m: Monoid<M>, f: (a: A) => M, list: A[]): M {
return list.map(f).reduce(m.binary, m.neutral)