This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE DerivingStrategies #-} | |
| import Data.Bits (toIntegralSized) | |
| import Data.Function ((&)) | |
| import Data.Kind (Type) | |
| import Data.Monoid (Sum (..)) | |
| import Data.Proxy (Proxy (..)) | |
| import Data.Sequence (Seq (..)) | |
| import Data.Sequence qualified as Seq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="module" async> | |
| // TODO: Fix error using `@codemirror/lang-markdown`: | |
| // ``` | |
| // Uncaught TypeError: Cannot read properties of undefined (reading 'deserialize') | |
| // at h (index.js:1585:48) | |
| // at new l (index.js:1600:29) | |
| // at l.deserialize (index.js:1841:16) | |
| // at index.js:252:25 | |
| // ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::fmt::{self, Display}; | |
| // TODO: Use tuples instead of arrays for heterogeneous lists | |
| // TODO: Escaping | |
| #[derive(Debug, PartialEq)] | |
| pub enum Html { | |
| Node(Node), | |
| Text(String), | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env nix-shell | |
| #!nix-shell -i ghcid -p ghcid "ghc.withPackages (p: with p; [ linear-base ])" | |
| -- Rough, imperfect re-implementation of this article on using Swift's | |
| -- "typestate" pattern. Haskell fails to replicate some aspects, and exceeds | |
| -- Swift's capabilities in other areas. | |
| -- | |
| -- https://swiftology.io/articles/typestate/ | |
| {-# LANGUAGE DataKinds #-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env nix-shell | |
| #!nix-shell -i runghc -p "ghc.withPackages (p: with p; [ safe-exceptions ])" | |
| {-# LANGUAGE BlockArguments #-} | |
| module Main (main) where | |
| import Control.Exception.Safe (Exception, MonadCatch, catch, throw) | |
| import Control.Monad (when) | |
| import Data.Dynamic (Typeable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use futures_lite::future::FutureExt as _; | |
| use std::future::{pending, ready}; | |
| enum Output { | |
| One(usize), | |
| Two(usize), | |
| Three(usize), | |
| } | |
| let one = async { Output::One(pending().await) }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::{ | |
| ops::{Deref, DerefMut}, | |
| sync::{ | |
| atomic::{AtomicBool, Ordering}, | |
| Arc, | |
| }, | |
| }; | |
| /// An `Option<T>` that behaves like a `T`. Avoid paying the cost of `Option` - no unwrapping or | |
| /// matching needed to access the value - when your value is present 99% of the time. For the rare |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data HList :: [Type] -> Type where | |
| HNil :: HList '[] | |
| HCons :: x -> HList xs -> HList (x : xs) | |
| infixr 5 `HCons` | |
| type (<>) :: [k] -> [k] -> [k] | |
| type family (<>) xs ys where | |
| (<>) '[] '[] = '[] | |
| (<>) (x : xs) '[] = x : xs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -Eeuo pipefail | |
| IFS=$'\n\t' | |
| if [ "$#" -ne 1 ]; then | |
| echo "usage: ./aoc-download <year>" >&2 | |
| exit 1 | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| macro_rules! key_modifiers { | |
| () => { | |
| ::crossterm::event::KeyModifiers::NONE | |
| }; | |
| ($m:ident) => { | |
| ::crossterm::event::KeyModifiers::$m | |
| }; | |
| ($m:ident | $($ms:ident)|+) => { | |
| ::crossterm::event::KeyModifiers::$m | crate::macros::key_modifiers!($($ms)|+) | |
| }; |