Skip to content

Instantly share code, notes, and snippets.

04785022ed95f0901f865f17542134a3fe9c70cf034cb3eda5e170417372e2abd9e972c6462cfe9b68fa340db25ccaf6d50cc024da358d883e0e15e8cea5a2ec
@mgsloan
mgsloan / simpleMapResult.hs
Last active July 28, 2021 03:00
Simplified function composition with variadic 2nd function (simplified but only works well for monomorphic arguments)
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
-- https://gist.github.com/mgsloan/7100f55c6ec12be8776a1a1c347cf963
-- for a more complex version with better type inference.
--
-- It was initially surprising to me that this one doesn't need the
-- "closed type family" trick to direct which instance is used. On
-- further thought,
@mgsloan
mgsloan / wrap.hs
Last active July 26, 2021 22:29
Function composition where 2nd function is variadic
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Proxy (Proxy(..))
@mgsloan
mgsloan / roam-navigator-theme.css
Created June 29, 2020 19:48
CSS for overriding Roam Navigator visual hint styles (https://github.com/mgsloan/roam-navigator). Can be used in extensions like Roam Toolkit (Custom CSS feature) or Stylish
.roam_navigator_hint {
color: purple !important;
font-size: 20px !important;
}
.roam_navigator_hint_typed {
color: orange !important;
}
.roam-sidebar-container .roam_navigator_hint, #right-sidebar .roam_navigator_hint {
@mgsloan
mgsloan / roam-backup.sh
Created June 22, 2020 04:42
Roam backup shell script
#!/bin/sh -e
# Script I wrote before I realized
# https://github.com/MatthieuBizien/roam-to-git exists
if [ "$#" -eq 1 ]; then
LAST_ROAM_EXPORT=$1
elif [ "$#" -eq 0 ]; then
echo "Attempting to use XDG info to find roam export."
# Load XDG dir configuration into variables
ErrorMonoidMaybeInt.hs:12:3-48: Splicing declarations
explainInstanceError [t| Monoid (Maybe Int) |]
======>
main_a6aM
= putStrLn
(displayInst
(resolveMonoid (Data.Proxy.Proxy :: Data.Proxy.Proxy (Maybe Int))))
class Semigroup_ a_a4Ra => Monoid_ (a_a4Ra :: GHC.Types.Type) where
resolveMonoid :: Data.Proxy.Proxy a_a4Ra -> Inst
instance OVERLAPPABLE #-} base-4.12.0.0:Data.Typeable.Internal.Typeable a_a4Ra =>
-- Context: https://github.com/ghc-proposals/ghc-proposals/pull/273#issuecomment-530215302
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Typeable
@mgsloan
mgsloan / desugar-local-types.md
Created September 11, 2019 04:11
Iffy desugaring idea for local types

Context: ghc-proposals/ghc-proposals#273 (comment)

I have not reviewed this proposal thoroughly, however I would really like this feature and have considered proposing it in the past. To make this more clearly defined and understandable for users, I'd like to propose a simple rule for what is allowed:

Local types could desugar to top level declarations

My intuition says that if this holds true then the feature becomes much easier to implement than if it does not. As far as I can tell this rule is mostly already followed in the proposal. Specifically:

All instances remain (conceptually) global, but they may involve local types and values

diff --git a/src/RIO.hs b/src/RIO.hs
index e4e2c66..e071714 100644
--- a/src/RIO.hs
+++ b/src/RIO.hs
@@ -1,3 +1,4 @@
+-- | This mo
module RIO
( module RIO.Prelude.Display
, module RIO.Prelude.Extra
diff --git a/src/RIO/Prelude/Reexports.hs b/src/RIO/Prelude/Reexports.hs
@mgsloan
mgsloan / keybase.md
Created January 2, 2018 05:34
keybase.md

Keybase proof

I hereby claim:

  • I am mgsloan on github.
  • I am mgsloan (https://keybase.io/mgsloan) on keybase.
  • I have a public key ASD0wSGDjAfr3397iicKObFGTTGmQyUVookmyd7W7GdH-go

To claim this, I am signing this object: