Skip to content

Instantly share code, notes, and snippets.

@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 (..))
@cky
cky / sha12.scm
Last active June 12, 2021 14:00
Scheme implementation of SHA1 and SHA2
;;;; SHA-1 and SHA-2 implementations.
;;;; Uses R7RS bytevector and byte I/O interfaces.
;;;; Requires SRFIs 1, 26, 43, and 60.
;;; Auxiliary definitions to avoid having to use giant tables of constants.
(define primes80 '(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73
79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157
163 167 173 179 181 191 193 197 199 211 223 227 229 233 239
241 251 257 263 269 271 277 281 283 293 307 311 313 317 331
@ahammar
ahammar / DesugarDo.hs
Created November 5, 2011 13:37
Naive do-notation desugarer
import Data.Generics
import Language.Haskell.Parser
import Language.Haskell.Pretty
import Language.Haskell.Syntax
main = do
input <- getContents
case parseModule input of
ParseOk mod -> putStrLn $ prettyPrint $ everywhere (mkT desugarExp) mod
ParseFailed loc msg -> failed loc msg