Skip to content

Instantly share code, notes, and snippets.

@lspitzner
lspitzner / kinds.txt
Created January 7, 2017 20:12
haskell kinds and example classes/inhabitants
kinds and their inhabitants
*
inhb: Bool, Int, Void, ..
clss: Num, Show, Eq, Typeable, Monoid, Semigroup, ..
* -> *
inhb: [], Maybe, Tree, ZipList, MVar, ST, IO, ..
clss: Functor, Monad, Foldable, Traversable, GMonoid, GShow, ..

my sublime setup for haskell includes:

  • SublimeHaskell, but with most features disabled. mostly for syntax highlighting. (as was pointed out, it is sufficient to grab the *theme file and omit the rest of the plugin. And even that is optional.)
  • for auto-formatting:
    • this (slightly modified) external-command plugin: https://github.com/lspitzner/SublimeExternalCommand
    • brittany (installed so that is on path)
    • the below keybind (you can open the user keybindings in sublime and merge the below)
    • you can either select some function and reformat that by pressing f9, or select nothing (whole file gets formatted)
  • for quick compilation feedback:
-- | Mask an event. The first parameter is the "masking event" that masks when
-- input events are forwarded to output events. The behavior constructed by
-- `stepper False mE` defines the masking period: When True, events can pass,
-- otherwise they are accumulated internally and can not pass.
-- As soon as the masking event switches from True to False, all accumulated
-- events get triggered simultaneously.
-- mask ************* *******
-- *** ********* *******
--
-- eIn v1 v2 v3 v4 v5
@lspitzner
lspitzner / _generate.sh
Last active February 26, 2020 13:13
fetch ghc proposal comments
# if you run this 5+ times, you will get rate-limited.
node fetch-comments.js
node process-comments.js > comments_.txt
cat comments_.txt | sed 's/#/\\#/g' | pandoc -f markdown -o comments.html
# Plus manual embedding into a html with <meta http-equiv="Content-Type" content="text/html; charset=utf-8">.
# Or serve with appropriate Content-Type.
@lspitzner
lspitzner / ContCatchT.hs
Created October 28, 2018 13:52
the ContCatchT monad
newtype ContCatchT r e m a =
ContCatchT { getContCatchT :: ((e -> m r) -> a -> m r) -> (e -> m r) -> m r }
instance Functor (ContCatchT r e m) where
fmap f (ContCatchT k) =
ContCatchT $ \c1 c2 -> k (\c3 -> c1 c3 . f) c2
instance Applicative (ContCatchT r e m) where
pure x = ContCatchT $ \c1 c2 -> c1 c2 x
ContCatchT cf <*> ContCatchT cx = ContCatchT
@lspitzner
lspitzner / GNTD.hs
Created October 10, 2018 18:32
GeneralizedNewtypeDeriving and roles
class A a where
a :: Monad m => a -> m a
instance A Int where
a = pure
newtype MyNewtype = MyNewtype Int deriving A
-- ^
-- error:
-- • Couldn't match representation of type ‘m Int’
createLimitedList
:: (MonadHold t m, MonadFix m, Adjustable t m)
=> IntMapS.Key
-> Event t (m ())
-> m ()
createLimitedList elemLimit e = do
let f a (_, i) =
( PatchIntMap $ IntMapS.fromList [(i - elemLimit, Nothing), (i, Just a)]
, i + 1
)
@lspitzner
lspitzner / nix-local-build.md
Last active July 29, 2018 23:46
nix-local-build
old-style new-style
install --only-dependencies part of new-build
install path-to-local-dir add a ./cabal.project file, add your local dependency, then use new-build (cabal.project syntax is described in the announcement)
install path-to-local-sdist does not exist yet
install remote-package-uri does not exist yet
install [--bindir=..] does not exist (yet)
configure new-configure
build (part of) new-build
clean does not exist yet; you have to remove ./dist-newstyle/ and ./cabal.project.local by hand, and potentially ./dist/ as well, i may have observed that it got touched by new-build (not sure, really). This needs to be done for each package referenced from the cabal.project as well.
@lspitzner
lspitzner / generate-qualified-imports.sh
Last active January 19, 2018 22:41
qualified imports in stackage package sources
#!/bin/bash
ls -1 stackage | xargs -I{} bash -c "find \"stackage/{}\" -type f -name \"*.hs\" -o -name \"*.lhs\"\
| xargs grep -h \"^import\" \
| grep \" as \" \
| sed \"s/ \+as//\" \
| sed \"s/^import \+\(qualified \+\)\?//\" \
| sort \
| uniq \
" \
-- the basic idea, without mentioning "comonad":
data RecEvent t a = RecEvent
{ rec_current :: a
, rec_next :: R.Event t (RecEvent t a)
}
foldRecEvent :: R.Reflex t => RecEvent t a -> R.PushM t (R.Dynamic t a)
foldRecEvent r1@(RecEvent _ e1) = do
e1' <- R.headE e1