Skip to content

Instantly share code, notes, and snippets.

@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
)
-- | 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

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:
-- 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
-- question: how could we define this type:
data DynamicFrom ts = ???
-- where this datatype needs to support the following interface:
-- wrap a HList-uncurried function. We'll probably need to somehow pack the
-- Dict (Typeable a) (rather: the TypeRep) as well.
packDynamicFrom :: Typeable a => (HList ts -> a) -> DynamicFrom ts
@lspitzner
lspitzner / MainReflex.hs
Created April 19, 2017 13:37
reflex design
brickWrapper
:: forall n t
. (Ord n, R.ReflexHost t, MonadIO (R.PushM t), MonadIO (R.HostFrame t))
=> R.Event t ()
-> R.Dynamic t [Widget n]
-> R.Dynamic t ([CursorLocation n] -> Maybe (CursorLocation n))
-> R.Dynamic t AttrMap
-> RH.AppHost
t
@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, ..