Skip to content

Instantly share code, notes, and snippets.

View zkbpkp's full-sized avatar

Daniil Kolesnichenko zkbpkp

  • Moscow, Russian Federation
View GitHub Profile
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
@cdepillabout
cdepillabout / example.nix
Last active February 7, 2023 03:52
Example of overriding a GHC core Haskell package with Nix
# This file is an example of overriding a GHC core Haskell library (like
# bytestring, containers, text, unix, etc) when building a Haskell package.
let default-nixpkgs =
builtins.fetchTarball {
# nixpkgs haskell-updates branch as of 2019/09/15.
url = "https://github.com/NixOS/nixpkgs/archive/a51b3367ab6acc72630da0bad50ce14fa86996d0.tar.gz";
sha256 = "05d3jxxk5dxzs9b3nan16lhkrjnzf0bjd4xy66az86fsafnrr9rd";
};
in
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE RankNTypes #-}
module Main where
import Data.Functor.Const
import Data.Functor.Identity (Identity (..))
import Data.Monoid
data Profile = Profile {user :: User}
lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
lens get set next value = fmap (set value) . next . get $ value
-- | A lens focusing on the first element in a pair
_1 :: Lens (a, x) (b, x) a b
_1 = lens fst (\(_, b) a -> (a, b))
-- | A lens focusing on the second element in a pair
_2 :: Lens (x, a) (x, b) a b
_2 = lens snd (\(a, _) b -> (a, b))