Skip to content

Instantly share code, notes, and snippets.

View ulysses4ever's full-sized avatar
🐢

Artem Pelenitsyn ulysses4ever

🐢
View GitHub Profile
@ulysses4ever
ulysses4ever / TcEnv.hs
Last active March 10, 2018 19:08
GHC: Tc-less version of lookupGlobal
lookupGlobal :: HscEnv -> Name -> IO TyThing
-- This may look up an Id that one one has previously looked up.
-- If so, we are going to read its interface file, and add its bindings
-- to the ExternalPackageTable.
lookupGlobal hsc_env name
= do { -- Try local envt
let mod = icInteractiveModule (hsc_IC hsc_env)
dflags = hsc_dflags hsc_env
tcg_semantic_mod =
if thisPackage dflags == moduleUnitId mod
@ulysses4ever
ulysses4ever / main.lhs
Last active June 23, 2018 11:28
Typeset Haskell code in LaTeX: an example of colorful lhs2TeX
% Build main.pdf:
% lhs2TeX main.lhs -o main.tex
% pdflatex main.tex
\documentclass{article}
%%%%%%%%%%%%%% Color-related things %%%%%%%%%%%%%%
\usepackage[dvipsnames]{xcolor}
@ulysses4ever
ulysses4ever / select.hs
Created June 29, 2018 10:59
`Selective` exercise: `select` of `handle`
import Data.Either (either)
import Data.Functor ((<$>))
class Applicative f => Selective f where
handle :: f (Either a b) -> f (a -> b) -> f b
select :: Selective f =>
f (Either a b) -> f (a -> c) -> f (b -> c) -> f c
select e fa fb = handle (Left <$> e) (either <$> fa <*> fb)
@ulysses4ever
ulysses4ever / convert-acm-dl-to-json.hs
Created July 27, 2018 11:45
Convert ToC in HTML from ACM DL to JSON (HotCRP/Researchr format)
{-#LANGUAGE DeriveGeneric, DuplicateRecordFields #-}
import Text.HTML.TagSoup
import Text.HTML.TagSoup.Match
import Data.List.Extra (chunksOf, trim)
import Generics.Pointless.Combinators (split)
import Data.Aeson (ToJSON, encode)
import GHC.Generics (Generic)
import Data.List (isInfixOf, isPrefixOf, find)
import Data.Char (isSpace)
{-#LANGUAGE DerivingVia #-}
module Main where
import Control.Monad.State
import Data.Functor.Identity
newtype Counter a = Counter (Int -> (a, Int))
deriving Functor via (State Int)
{-
import System.Environment (getArgs)
{-# OPTIONS_GHC -funbox-strict-fields #-}
data Nat = Zero | Succ !Nat deriving (Show)
fromNat :: Nat -> Integer
fromNat Zero = 0
fromNat (Succ n) = fromNat n + 1
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.ST
import Control.Exception
import System.Random
import Data.Functor
import qualified Data.Vector.Generic.Mutable as V
import qualified Data.Vector.Unboxed as U
{-# LANGUAGE BangPatterns #-}
class Mergeable a where
mergeAppend :: a -> a -> a
mergeAppend _a b = b
instance Mergeable Bool
instance Mergeable a => Mergeable (Maybe a) where
mergeAppend = mayMerge
artem@prl-julia:~/Dev/ghc/ghc-duplicate-packages-t18125-t16318-3$ cat pe-r
clear-package-db
global-package-db
package-db /home/artem/.cabal/store/ghc-8.10.1/package.db
package-id base-4.14.0.0
package-id random-1.1-f453c042ea8c8bf59e5bb793c33f7ae4920ff92b828974833161b30ea32713ba
artem@prl-julia:~/Dev/ghc/ghc-duplicate-packages-t18125-t16318-3$ cat Main.hs
import System.Random
main :: IO ()
{-# LANGUAGE RecordWildCards, FlexibleContexts #-}
-- The Computer Language Benchmarks Game
-- https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
--
-- Contributed by cahu ette
module Main where