Skip to content

Instantly share code, notes, and snippets.

View cblp's full-sized avatar

Yuriy Syrovetskiy cblp

  • Montenegro
View GitHub Profile
@cblp
cblp / OpenUnionAst.hs
Last active October 30, 2020 13:53
open-union AST
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.OpenUnion (Union, liftUnion)
import Data.Singletons.Prelude (type (++))
-- * Union's Little helpers
type family a \/ b where
Union xs \/ Union ys = Union (xs ++ ys)
@cblp
cblp / .hs
Last active October 30, 2020 11:16
Final Tagless AST
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
class ArithOp op where add, mul :: op
class LogicalOp op where and :: op
class CompareOp op where less, equal :: op
@cblp
cblp / Final Tagless Tree.hs
Last active October 30, 2020 08:38
Final Tagless Tree
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTSyntax #-}
-- * (G)ADT
data DTree where
Empty :: DTree
Node :: String -> DTree -> DTree -> DTree
deriving (Show)
@cblp
cblp / error
Last active October 23, 2020 11:17 — forked from YuraKostin/error
Will Kurt. Lesson 10
robots.hs:47:36: error:
• Couldn't match type ‘[Char]’
with ‘((a1, b1, [Char]) -> t1) -> t1’
Expected type: ((a1, b1, [Char]) -> ((a1, b1, [Char]) -> t1) -> t1)
-> ((((a1, b1, [Char]) -> t1) -> t1, b1,
((a1, b1, [Char]) -> t1) -> t1)
-> ((a1, b1, [Char]) -> t1) -> t1)
-> [Char]
Actual type: ((((a1, b1, [Char]) -> t1) -> t1, b1,
((a1, b1, [Char]) -> t1) -> t1)
#include <list>
using std::list;
#include <map>
using std::map;
#include <set>
using std::set;
#include <utility>
using std::pair;
#include <rapidcheck.h>
@cblp
cblp / Meta.hs
Last active February 21, 2020 06:48
Transparent type annotations in Haskell
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Meta where
import Control.Monad
import Language.Haskell.TH
type a // b = a
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import Data.Kind
import Data.List
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module A where
import Data.ByteString
import Language.C.Inline as C
@cblp
cblp / parseExpr.hs
Last active October 23, 2019 12:09
#!/usr/bin/env stack
{-
stack --resolver=lts-14.10
script --ghc-options=-Wall --package=megaparsec --package=parser-combinators
-}
import Control.Monad.Combinators ((<|>), between, some)
import Control.Monad.Combinators.Expr (Operator (InfixL), makeExprParser)
import Data.Void (Void)
import Text.Megaparsec (Parsec, eof, errorBundlePretty, parse)
@cblp
cblp / id.hs
Created September 26, 2019 12:12
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedLabels #-}
import Control.Lens
import Data.Generics.Labels
import GHC.Generics
import Prelude hiding (id)
import qualified Prelude