This file contains 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
-- | A note: This is pretty much strictly worse than the functionality | |
-- offered by <hackage.haskell.org/package/async> . Use this library if | |
-- you cannot be bothered to depend on async. | |
module Timeout where | |
import Control.Concurrent | |
import Control.Exception | |
data TimeoutException = TimeoutException Int | |
instance Show TimeoutException where |
This file contains 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 TypeFamilies #-} | |
module Dyck where | |
import Control.Applicative hiding (many) | |
import Control.Monad | |
import Data.Void | |
import Text.Megaparsec | |
import Text.Megaparsec.Char | |
newtype Dyck = Some [Dyck] |
This file contains 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
-- | |
-- Is there a more efficient/elegant way to do this? | |
-- | |
-- Objective: To disable/enable the mouse cursor for specific windows | |
-- | |
checkMouseDisable :: X () | |
checkMouseDisable = do |
This file contains 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 Expr = Val Double | Op (Double -> Double -> Double) Expr Expr | |
binOpP :: Parser (e -> e -> e) -- ^ binary operator | |
-> Parser e -- ^ parser for operands | |
-> Parser e | |
binOpP opP elP = do | |
x <- elP | |
asum | |
[ do op <- opP; y <- binOpP opP elP; pure (op x y) | |
, pure x |
This file contains 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 OverloadedLabels #-} -- other extensions omitted | |
import Data.Kind | |
import GHC.OverloadedLabels | |
import GHC.TypeLits | |
infix 1 ::# | |
data NamedType = Symbol ::# Type | |
data Tag (t :: NamedType) where Tag :: Tag t | |
instance IsLabel s (Tag t) where |
This file contains 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 FunctionalDependencies #-} | |
{-# language KindSignatures #-} | |
{-# language DerivingVia #-} | |
{-# language ScopedTypeVariables #-} | |
{-# language TypeApplications #-} | |
-- some extensions elided, GHC should tell you what they are | |
module Capability where | |
import Control.Monad.Reader | |
import Control.Monad.State |
This file contains 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
newtype Pointwise f a = Pointwise { getPointwise :: f a } | |
deriving newtype (Functor, Applicative, Alternative, Monad, MonadPlus, MonadZip) | |
deriving stock (Eq, Ord, Show, Read) | |
instance (MonadZip f, Semigroup a) => Semigroup (Pointwise f a) where | |
Pointwise xs <> Pointwise ys = Pointwise (mzipWith (<>) xs ys) | |
-- Now Maybe (Pointwise (Vector (Sum a))) is the monoid you're looking for |
This file contains 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
import GHC.Exts (Any) | |
import Unsafe.Coerce (unsafeCoerce) | |
import Control.Monad.State | |
import Data.IntMap (IntMap) | |
import qualified Data.IntMap (IntMap) | |
-- Don't export /any/ of these constructors! | |
type role ST' nominal representative |
This file contains 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
#!/bin/env stack | |
-- stack script --resolver lts-12.16 --package scotty --install-ghc | |
{-# LANGUAGE OverloadedStrings #-} | |
import Web.Scotty | |
main = scotty 80 $ do | |
get "/" $ do | |
html $ "Hello World!" |
This file contains 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
module Finite where | |
-- | A simple natural number type | |
data N = Z | S N deriving (Eq, Ord) | |
-- | A simple length-indexed "vector" | |
data Vec n a where | |
VZ :: Vec Z a | |
VS :: a -> Vec n a -> Vec (S n) a |