Skip to content

Instantly share code, notes, and snippets.

View dmwit's full-sized avatar

Daniel Wagner dmwit

View GitHub Profile
(.) :: (b -> c) -> (a -> b ) -> (a -> c)
(,) :: d -> (e -> (d,e))
so a ~ d, and b ~ e -> (d,e), and
\x -> x . (,) :: ((e -> (d,e)) -> c) -> (d -> c)
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeFamilies #-}
import GHC.Types
class Foo f where
type Ctx f i :: Constraint
extract :: Ctx f i => i -> f i -> String
newtype Los i = Los [String] deriving (Eq, Ord, Read, Show)
{-# LANGUAGE DeriveFunctor #-}
import Control.Monad.Zip
data Zip f a = P a | V (f a)
deriving (Eq, Ord, Read, Show, Functor)
instance MonadZip f => Applicative (Zip f) where
pure = P
P f <*> P x = P (f x)
P f <*> V xs = V (f <$> xs)
foldb1 op = foldb' where
pairwise (x:y:rest) = op x y : pairwise rest
pairwise shortList = shortList
foldb' xs@(_:_:_) = foldb' (pairwise xs)
foldb' [x] = x
foldb op def xs = foldb1 op (def:xs)
find fp = do
entry <- entityFromFile fp
mold <- lookupEntity (entityHash entry)
pure $ case mold of
Nothing -> ImportAdded entry
Just old | entityPath old == entityPath entry -> ImportUpToDate entry
_ -> ImportMoved old entry
act (ImportAdded entry) = do
dbPutEntity entry
< dmwit> Okay, so "graphical" characters are allowed, which means letters (lower- and upper-case), symbols, punctuation, decimal digits, and a handful of one-off exceptions.
< dmwit> PrivateUse doesn't qualify as any of those categories. (And you can use generalCategory to check any particular character you want to know about.)
< dmwit> The relevant production in the Report is "graphic" at https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-160002.2
< geekosaur> yeh. I actually consider this a ghc wart; it should allow PrivateUse in literals. I end up using escapes in my config
< dmwit> > nub $ generalCategory <$> [minBound..]
<+lambdabot> [Control,Space,OtherPunctuation,CurrencySymbol,OpenPunctuation,ClosePunctuat...
< geekosaur> maybe a Haskell wart if the Report specs this; there's no good reason a Char or String literal shouldn't allow any valid Unicode character
< geekosaur> (note that this does not mean allowing PrivateUse anywhere else in a lexical Haskell setting, ecept maybe comments
@dmwit
dmwit / typeappvsproxy.hs
Last active December 23, 2019 19:07
TypeApplications how?
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
data Nat = O | S Nat
type family xs ++ ys where
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
data Nat = O | S Nat
@dmwit
dmwit / gist:cb7e2a9e70acb004ba5ddd07aea1ec7c
Created April 16, 2020 08:27
can somebody explain this to me please?
% cat /proc/24430/cmdline | cut -b1-30
nurse-sveta-multi-play-t0.75
% pgrep sveta-mul
24430
% pgrep sveta-mult
zsh: exit 1 pgrep sveta-mult
% cat /proc/24430/cmdline | cut -b1-30
nurse-sveta-multi-play-t0.75
--- test.hs.old 2020-04-16 20:27:41.179931585 -0400
+++ test.hs.new 2020-04-16 20:29:04.908156993 -0400
@@ -88,17 +88,17 @@
play (play_movement board Player (read col::Int)) Machine strat
--WIP
-machine_turn :: Board -> Strategy -> Board
+machine_turn :: Board -> Strategy -> IO Board
machine_turn board Random = machine_random_ia board