Skip to content

Instantly share code, notes, and snippets.

@lspitzner
lspitzner / A_multistate-benchmark.txt
Last active May 28, 2016 14:38
some basic multistate benchmarking
------------------
run-time: criterion results
------------------
benchmarking extensible-effects
time 1.337 s (1.308 s .. 1.387 s)
1.000 R² (1.000 R² .. 1.000 R²)
mean 1.314 s (1.304 s .. 1.322 s)
std dev 13.22 ms (0.0 s .. 14.55 ms)
variance introduced by outliers: 19% (moderately inflated)
@lspitzner
lspitzner / a.txt
Created July 1, 2016 20:02
sublime3+ghcid setup for quick haskell coding feedback
sublime3 and ghcid setup for quick haskell coding feedback
tested on sublime 3
(you can omit the SublimeOnSaveBuild steps, as the result is not
completely reliable anyways. i still find it useful, though.)
steps:
- install https://github.com/lspitzner/SublimeOnSaveBuild
(original from alexnj; in his/her version the build-window gets closed
@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, ..
@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
-- 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
-- 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

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
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 / 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’