Skip to content

Instantly share code, notes, and snippets.

View qnikst's full-sized avatar
🐧
penguin?

Alexander Vershilov qnikst

🐧
penguin?
View GitHub Profile
@qnikst
qnikst / Rev-deps.hs
Created November 3, 2017 10:09
Build reverse hierarchy
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
@qnikst
qnikst / v-stream.hs
Last active October 22, 2017 14:43
special-olympics
{-# Language OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
module Main where
import qualified Data.ByteString.Char8 as BS8
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.FastBuilder as Builder
-- import qualified Data.ByteString.Builder.Extra as Builder
import Data.ByteString.Char8 (ByteString)
import Data.Monoid ((<>))
@qnikst
qnikst / 1.hs
Created September 18, 2017 22:24
some singletons
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
@qnikst
qnikst / storage.hs
Created May 17, 2017 06:25
Simple storage that you can use to control concurrent evaluations.
import Control.Concurrent.Async
import Control.Concurrent.STM
import Control.Exception
import Control.Monad
import qualified Data.Map as Map
import Data.Map (Map)
import System.IO.Unsafe
-- | Version1 - starts async only when it's evaluated
-- Composable
@qnikst
qnikst / lol.hs
Last active February 24, 2017 07:13 — forked from s9gf4ult/lol.hs
TF (juick : http://juick.com/segfault/2863032#5)
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Time
type family TimeDiff a where
TimeDiff UTCTime = NominalDiffTime
TimeDiff a = a
@qnikst
qnikst / l1.idr
Created February 19, 2017 08:15
linear-types sort
module l1
data UL : Nat -> UniqueType -> UniqueType where
Nil : {a:UniqueType} -> UL Z a
(::) : {a:UniqueType} -> a -> UL k a -> UL (S k) a
data UNat : UniqueType where
UZ : UNat
US : UNat -> UNat
@qnikst
qnikst / 1.hs
Last active February 7, 2017 22:51
A bit of hetero reading
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
import Data.List
{-# LANGUAGE ForeignFunctionInterface #-}
import Foreign
import Foreign.C
foreign import ccall "wrapper" cwrap :: (CInt -> IO CInt) -> IO (FunPtr (CInt -> IO CInt))
foreign import ccall "inside" inside :: FunPtr (CInt -> IO CInt) -> IO ()
foreign import ccall "another" another :: IO ()
waiting :: CInt -> IO CInt
@qnikst
qnikst / 1.hs
Created January 22, 2016 16:51
data ExceptionInfo = ExceptionIf ThreadId SomeException -- constructor should be hidden
throwToEnclosed :: Exception e => ThreadId -> e -> IO ()
throwToEnclosed to ex =
throwTo =<< ExceptionInfo <$> myThreadId <*> pure (SomeException ex)
enclosed :: [ThreadId] -> IO a -> IO a
enclosed allowed f = mask $ \release -> do
result <- newEmptyMVar
@qnikst
qnikst / Foo.hs
Last active January 10, 2016 19:13 — forked from max630/Foo.hs
attempt to use DataKinds
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
module Foo where