Skip to content

Instantly share code, notes, and snippets.

zipRev :: [a] -> [b] -> [(a,b)]
zipRev xs ys = fr where
(fr, allbs) = go [] allbs xs ys
go acc ~(b':bs') (a:as) (b:bs) = ((a,b') : res, bss)
where
(res, bss) = go (b:acc) bs' as bs
go acc _ _ _ = ([], acc)
@treeowl
treeowl / Bftr.hs
Last active March 16, 2020 09:11
Breadth-first binary tree creation
-- | This module defines a function that produces a complete binary tree
-- from a breadth-first list of its (internal) node labels. It is an
-- optimized version of an implementation by Will Ness that avoids
-- any "impossible" cases. See
--
-- https://stackoverflow.com/a/60561480/1477667
module Bftr (Tree (..), bft, list, deftest) where
import Data.Function (fix)
import Data.Monoid (Endo (..))
{-# language GADTs, ScopedTypeVariables, DeriveTraversable #-}
module ChallengeTransform where
import Data.Typeable
import Data.Proxy
import Data.Coerce
data Scheme a where
Res :: Typeable a => !(Proxy a) -> Scheme a
Arg :: Typeable a => !(Proxy a) -> Scheme b -> Scheme (a -> b)
@treeowl
treeowl / Generic1.hs
Last active October 15, 2021 06:07
Implementing Generic1 using Generic
{-# language EmptyCase #-}
{-# language FlexibleContexts #-}
{-# language FlexibleInstances #-}
{-# language InstanceSigs #-}
{-# language MultiParamTypeClasses #-}
{-# language PolyKinds #-}
{-# language QuantifiedConstraints #-}
{-# language ScopedTypeVariables #-}
{-# language StandaloneKindSignatures #-}
{-# language TypeApplications #-}
@treeowl
treeowl / gist:b092eade5ec4bf429eb8351e50909240
Last active April 6, 2023 18:22
Pairing queues with linear interface
{-# language BangPatterns #-}
{-# language LinearTypes #-}
{-# language GADTs #-}
{-# language StandaloneKindSignatures #-}
{-# language KindSignatures #-}
{-# language TypeApplications #-}
{-# language DataKinds #-}
{-# language ScopedTypeVariables #-}
-- | Pairing heap loosely based on one Donnacha Oisín Kidney wrote for