Skip to content

Instantly share code, notes, and snippets.

Avatar
🏳️‍🌈

Antoine Leblanc nicuveo

🏳️‍🌈
View GitHub Profile
@nicuveo
nicuveo / oh_no.hs
Created May 27, 2021
TypeApplications bug?
View oh_no.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
module Foo where
import Control.Monad.Reader
import Data.Kind (Type)
View GADTs-Typeable.hs
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
@nicuveo
nicuveo / Makefile
Created Jan 27, 2021
Repro case for redundant constraint bug.
View Makefile
all:
ghc --version
ghc -Wredundant-constraints -Werror -O0 Main.hs
ghc -Wredundant-constraints -Werror -O2 Main.hs
View TypeLevelContains.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Kind (Type)
import Data.Type.Bool
View RuntimeTypeContains.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
import Data.Proxy
import Data.Typeable
contains :: forall a b. (Typeable a, Typeable b) => Bool
contains = go typeB
where typeA = typeRep (Proxy :: Proxy a)
@nicuveo
nicuveo / Main.hs
Last active Dec 18, 2021
Minimalistic JSON parser, using a Parsec-like approach
View Main.hs
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
import Control.Applicative (liftA2)
import Data.Char
import Data.Foldable (for_)
import Data.Functor
import qualified Data.HashMap.Strict as M
import Data.List (intercalate)
import Prelude hiding (any)
View failCTDuplicateTrigger
{"type":"http-log","timestamp":"2020-03-31T00:05:40.203+0000","level":"error","detail":{"operation":{"user_vars":{"x-hasura-role":"admin"},"error":{"internal":{"statement":"DO $$ DECLARE r RECORD; BEGIN FOR r IN (SELECT routine_name FROM information_schema.routines WHERE specific_schema = 'hdb_views' ORDER BY routine_name) LOOP EXECUTE 'DROP FUNCTION hdb_views.' || quote_ident(r.routine_name) || '() CASCADE'; END LOOP; END $$; ","prepared":false,"error":{"exec_status":"FatalError","hint":null,"message":"cannot execute DROP FUNCTION in a read-only transaction","status_code":"25006","description":null},"arguments":[]},"path":"$.args[0].args","error":"postgres query error","code":"unexpected"},"request_id":"51d1a76d-8688-4905-a913-f1be94bc8df5","response_size":566,"query":{"args":[{"args":{"cascade":false,"check_metadata_consistency":null,"sql":"SELECT\n COALESCE(Json_agg(Row_to_json(info)), '[]' :: json) AS tables\nFROM (\n SELECT\n pgn.nspname as table_schema,\n pgc.relname as table_name,
@nicuveo
nicuveo / FizzBuzz_2.hs
Created Oct 3, 2019
Haskell type-level fizzbuzz, version 2
View FizzBuzz_2.hs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE UndecidableInstances #-}
-- no data kinds, pure type level
-- let's start by defining booleans and numbers
data True
@nicuveo
nicuveo / FizzBuzz_1.hs
Last active Oct 3, 2019
Haskell type-level fizzbuzz, version 1
View FizzBuzz_1.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import Data.Proxy
import GHC.TypeLits
View Indexable.hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ParallelListComp #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}