Skip to content

Instantly share code, notes, and snippets.

View Elvecent's full-sized avatar

Kirill Valiavin Elvecent

View GitHub Profile
@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 / 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 / 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 / haskell.md
Last active January 14, 2020 10:00
Minimal Haskell Emacs

Minimal Haskell Emacs configuration, from scratch

This little instruction shows how to set up Emacs with some packages to start writing Haskell in a more or less convenient way (including, but not limited to: smart auto completion, type info, autoformatting).

Get emacs

First step: get Emacs for your platform. This should be simple.

Find your init file

That's usually ~/.emacs on unix-like systems. ~ stands for "home folder" and on Windows it's usually AppData\Roaming. Check this out.

Set up MELPA

@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
@Elvecent
Elvecent / Main.hs
Last active March 20, 2021 10:02
Selecting
import Control.Lens
import Data.Monoid
import Data.List.Extra
import Data.Foldable
select as fbs f s =
flip as s $ \a -> a <$ (
flip (fbs a) s $ \b ->
snd <$> f (a,b)
)