Skip to content

Instantly share code, notes, and snippets.

View rebeccaskinner's full-sized avatar

Rebecca Skinner rebeccaskinner

View GitHub Profile
@rebeccaskinner
rebeccaskinner / Len.hs
Created May 13, 2024 14:47
Compare lengths of finite and infinite lists
data Length = forall x. Length { unLength :: [x] }
instance Eq Length where
(==) (Length []) (Length []) = True
(==) (Length (_:xs)) (Length (_:ys)) = Length xs == Length ys
(==) _ _ = False
instance Ord Length where
compare (Length []) (Length []) = EQ
compare (Length (_:_)) (Length []) = GT
@rebeccaskinner
rebeccaskinner / BKTree.hs
Created October 17, 2024 15:30
Naive BKTree implementation in Haskell
module Data.BKTree where
import Prelude hiding (lookup)
import Text.Printf
data BKTreeData d a where
Node :: a -> [(d, BKTreeData d a)] -> BKTreeData d a
deriving Show
insertWithMetric :: (Eq d, Num d) => (a -> a -> d) -> a -> BKTreeData d a -> BKTreeData d a
insertWithMetric metric val t@(Node nodeVal children)
@rebeccaskinner
rebeccaskinner / Sized.hs
Created October 18, 2024 18:53
Simple Sized Vector
{-# LANGUAGE NoStarIsType #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
module Data.Vector.Sized where
import Prelude hiding (take, map)
import Data.Vector (Vector)
import Data.Vector qualified as Vec
import Data.Kind