Skip to content

Instantly share code, notes, and snippets.

View monadplus's full-sized avatar

Arnau Abella monadplus

View GitHub Profile
@monadplus
monadplus / example.sql
Created February 3, 2020 11:54
PostgreSQL: functions don't hold static references to the objects.
create table a (isOk BOOLEAN not null);
CREATE or replace FUNCTION get_isOk ( )
returns BOOLEAN as $$
select isOk from faa;
$$ LANGUAGE SQL;
drop table a;
-- select get_isOk(); -- now fails
@monadplus
monadplus / gadts_type_equality.hs
Created February 3, 2020 12:55
GADTs, Constraints and type equality.
-- CONSTRAINT kind:
-- * fully-saturated typeclasses
-- * tuples of other CONSTRAINTS
-- * type equalities.
-- In regular haskell this is restricted:
-- 1. We can't mention type variables in the arguments unless they're also in
-- the result.
-- 2. We can't /constrain/ the values of the input using any typeclasses.
@monadplus
monadplus / ClassSynonyms.hs
Created February 3, 2020 14:41
Class Synonyms
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
module ClassSynonyms where
-- This is bordersome to write every time..
-- f :: (C1 a, C2 a, C3 a) => ...
-- class synonyms
class (C1 a, C2 a, C3 a) => C a where { }
instance (C1 a, C2 a, C3 a) => C a where { }
@monadplus
monadplus / nixops.md
Last active February 4, 2020 18:47
NixOps: where is it compiling the derivation ? Remote Builds

NixOps Compilation

If the machine running nixOps is linux, it will build it locally, but also obey any build machines configured in /etc/nix/machines.

If nixops is being ran on darwin/windows, it cant build linux things, so it will try to configure the remote machine as a build machine, automatically.

There is a workaround for this if you don't won't to compile on your sever (for example, if the instances is too small it will fail): set a remote build machine over ssh.

To set up a remote build read these links:

@monadplus
monadplus / profiling_haskell.md
Last active May 2, 2024 19:41
Haskell: Profiling

Profiling in Haskell

Do not get bogged down in microoptimizations before you've assessed any macro optimizations that are available. IO and the choice of algorithm dominate any low level changes you may make. In the end you have to think hard about your code!

Before starting to optimize:

  1. Is the -O2 flag on ?
  2. Profile: which part of the code is the slow one.
  3. Use the best algorithm in that part.
  4. Optimize: implement it in the most efficient way.
@monadplus
monadplus / crossing-the-chasm.md
Created February 5, 2020 12:41
Crossing the Chasm

Crossing the Chasm

  1. Compeling reason to buy
  2. Very specific target
  3. Polish whole product
  4. Not a leader on the space you are trying to occupy
@monadplus
monadplus / lateral_join.md
Created February 6, 2020 13:20
Lateral Join

LATERAL JOIN

Data:

                Table "public.orders"
   Column   |            Type             | Modifiers
------------+-----------------------------+-----------
 id         | integer                     | not null
 user_id    | integer                     |
@monadplus
monadplus / instance_resolution-corner_case.md
Last active February 10, 2020 07:15
Instance resolution corner case
@monadplus
monadplus / a.md
Created February 18, 2020 17:20
Setup a development environment for Python in NixOS: failed tries
@monadplus
monadplus / parser.hs
Created February 27, 2020 08:06
Simple Parser
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE ScopedTypeVariables #-}
type Input = String
data ParseResult a =