Skip to content

Instantly share code, notes, and snippets.

View Elvecent's full-sized avatar

Kirill Valiavin Elvecent

View GitHub Profile
@Elvecent
Elvecent / Main.hs
Created August 15, 2019 20:08
Cool coroutines with free monad transformers
-- packages "free" and "transformers" assumed
{-# LANGUAGE DeriveFunctor #-}
module Main where
import Control.Monad.Trans.Free
import Control.Monad.Trans.Class
data CoroutineF a = Yield a
@Elvecent
Elvecent / Main.hs
Last active September 14, 2019 10:46
Free Monad & Cofree Comonad
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Main where
@Elvecent
Elvecent / Concurrent.hs
Last active September 1, 2019 23:52
Running jobs asynchronously but yielding results in order
module Utils.Concurrent (mkPipeline, launchNukes) where
import Control.Concurrent (threadDelay)
import Control.Concurrent.Async (Async, async, cancel, wait)
import Control.Concurrent.STM (TBQueue, atomically, newTBQueueIO,
readTBQueue, writeTBQueue)
import Control.Monad (forever, void)
import Control.Monad.IO.Class (MonadIO, liftIO)
import GHC.Natural (Natural)
@Elvecent
Elvecent / Pure.hs
Created September 11, 2019 12:14
Deep Pure Fun
{-# LANGUAGE TypeApplications, DataKinds, KindSignatures, TypeFamilies, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}
module Main where
import Data.Functor.Compose
import Data.Functor.Identity
import Data.Coerce
data Nat = Zero | Succ Nat
@Elvecent
Elvecent / App.tsx
Last active October 28, 2019 11:38
Nice React counter
import { createContext, useContext, useReducer } from "react";
import * as React from "react";
import { render } from "react-dom";
// <LibraryCode>
const StateContext: React.Context<[any, React.Dispatch<any>]> = createContext(
undefined
);
function StateProvider<S, A>({
@Elvecent
Elvecent / Main.hs
Created November 13, 2019 06:02
Minesweeper
module Main where
-- from "monoidal-containers" package
import qualified Data.IntMap.Monoidal.Strict as M
-- The thing with this IntMap is that whenever
-- its elements form a semigroup, the IntMaps
-- containing those elements themselves form
-- a monoid that works "pointwise"
-- Just type synonyms
@Elvecent
Elvecent / Server.hs
Created December 6, 2019 13:34
WebSocket chat that fails
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Server (talk, newServer, Server) where
import Control.Concurrent.Async
import Control.Concurrent.STM
import Control.Exception
import Control.Monad
import Data.Foldable (traverse_)
import Data.Functor (void)
@Elvecent
Elvecent / Main.hs
Last active August 15, 2020 21:34
Functor list product or idk
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ConstraintKinds #-}
@Elvecent
Elvecent / default.nix
Created November 16, 2020 20:36
Haskell Nix
{ nixpkgs ? import ./nix/nixpkgs-2020-09.nix
, hls ? true
, hoogle ? true
}:
let
packageName = "template";
overlay = self: super: {
myHaskellPackages =
@Elvecent
Elvecent / Main.hs
Last active March 20, 2021 09:54
Parsing
import Data.Void
import Text.Megaparsec
import Text.Megaparsec.Char
type Parser = Parsec Void String
main :: IO ()
main = case runParser p "bruh" "\"123\", \"321\" , ," of
Left err -> print err
Right res -> print res