Skip to content

Instantly share code, notes, and snippets.

View maksbotan's full-sized avatar

Maxim Koltsov maksbotan

View GitHub Profile
@maksbotan
maksbotan / aeson-via.hs
Created December 26, 2019 13:24
aeson deriving via
{-# LANGUAGE DeriveGeneric, DerivingVia, FlexibleInstances, UndecidableInstances #-}
import Data.Aeson
import Data.Aeson.Casing
import GHC.Generics
newtype CamelCaseJson a = CamelCaseJson a
deriving (Eq, Show, Generic)
instance (GToJSON Zero (Rep a), Generic a) => ToJSON (CamelCaseJson a) where
@maksbotan
maksbotan / enums.md
Created December 30, 2019 07:19
Generic валидация

Валидация enum'ов во вложенных структурах

Про этот файл

Это Literate Haskell файл. Вот как загрузить его в ghci:

$ stack --resolver=lts-13.6 install markdown-unlit
$ stack --resolver=lts-13.6 ghci enums.md --package aeson --package validation --package semigroups --package containers --package lens --package generic-lens --ghci-options='-pgmL markdown-unlit'
@maksbotan
maksbotan / val.py
Created February 6, 2020 05:57
Example of type-level validation in python
from dataclasses import dataclass
from typing import Generic, Optional, TypeVar
class Raw:
pass
class Valid:
pass
@maksbotan
maksbotan / generic-validation.md
Last active July 5, 2020 20:34
Generic validation of nested data

Generic validation of nested data

TLDR

This technique helps validate arbitrary conditions in deeply nested structures without writing additional code — with the help of Haskell Generics.

It boils down to this pattern:

@maksbotan
maksbotan / typecheck.py
Created April 8, 2020 15:23
Simplistic python typechecking
import ast
import sys
from enum import Enum
from typing import Dict, NamedTuple, Union
class PrimType(Enum):
ty_int = "int"
ty_bool = "bool"
@maksbotan
maksbotan / hls.patch
Created April 27, 2022 10:56
Haskell Language Server + haskell.nix patch
diff --git a/ghcide/src/Development/IDE/Core/Compile.hs b/ghcide/src/Development/IDE/Core/Compile.hs
index 99938bd4..471b184c 100644
--- a/ghcide/src/Development/IDE/Core/Compile.hs
+++ b/ghcide/src/Development/IDE/Core/Compile.hs
@@ -122,6 +122,15 @@ import GHC.Hs (LEpaComment)
import qualified GHC.Types.Error as Error
#endif
+import StgSyn
+import FastString