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 |
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
-- First: split fundeps with multiple types on the RHS, like so: | |
-- LHS -> x0 x1 ... xn | |
-- becomes: | |
-- LHS -> x0, LHS -> x1, ..., LHS -> xn | |
-- now every fundep is of the form 'd0 d1 ... dn -> x' | |
-- Turn every such fundep into an open type family: | |
-- type family Cls_FD_k d0 d1 ... dn | |
-- and add an equality constraint 'x ~ Cls_FD_k d0 d1 ... dn'. | |
-- In some cases (generally speaking, when the fundeps do not form a cycle), | |
-- the type family can be inlined, replacing all uses of 'x' with 'Cls_FD_k d0 d1 ... dn'. |