This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE AllowAmbiguousTypes #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
data Nat = O | S Nat | |
type family xs ++ ys where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
< 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(.) :: (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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype A = A Int | |
newtype B = B Int | |
type Database = String | |
type JSON = String | |
class ParseDatabase a where parse :: Database -> Maybe a | |
instance ParseDatabase A where parse db = A <$> readMaybe s | |
instance ParseDatabase B where parse db = B <$> readMaybe s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
derangements :: Integer -> Integer | |
derangements n = id | |
. sum | |
. zipWith (*) signs | |
. scanl (*) 1 | |
$ [n,n-1..1] | |
where | |
signs = drop (n .&. 1) (cycle [1,-1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c (1, 1) = 1 | |
c (2, 2) = 1 | |
c (i, 1) | i > 2 = -(a ! (i-2, 1)) | |
c (i, j) | i == j = 2 * (a ! (i-1, j-1)) | |
| i > j && j > 1 = 2 * (a ! (i-1, j-1)) - (a ! (i-2, j-1)) | |
| otherwise = 0 |