Skip to content

Instantly share code, notes, and snippets.

View Pitometsu's full-sized avatar
🐫
∀:camel:.P(:camel:) → ∅ ≡ (∃:camel:.P(:camel:)) → ∅

Yuriy Pitomets Pitometsu

🐫
∀:camel:.P(:camel:) → ∅ ≡ (∃:camel:.P(:camel:)) → ∅
View GitHub Profile
@Pitometsu
Pitometsu / example.ml
Created September 19, 2019 20:42
Can module-level have Upper Type Bounds
utop#
module type T = sig
type t = ..
end;;
module type T = sig type t = .. end
utop #
@Pitometsu
Pitometsu / wtf.sh
Created September 18, 2019 11:51
Darwin stdlib problem
$ nix-shell -p gcc8 --command 'echo $NIX_CFLAGS_COMPILE'
-isystem /nix/store/aj932q5vd2xzl67v3qs6hsg47lxmf0n2-libc++-5.0.2/include -isystem /nix/store/89gnz8abjwra67d8y6s6ysmjl6ji81ai-libc++abi-5.0.2/include -isystem /nix/store/yr2vwrbjgabcskp153nzsyl72ysbfc1g-compiler-rt-5.0.2-dev/include -F/nix/store/7x42k0scp8xscrf092jalvpns4cwnnj3-swift-corefoundation/Library/Frameworks -isystem /nix/store/aj932q5vd2xzl67v3qs6hsg47lxmf0n2-libc++-5.0.2/include -isystem /nix/store/89gnz8abjwra67d8y6s6ysmjl6ji81ai-libc++abi-5.0.2/include -isystem /nix/store/yr2vwrbjgabcskp153nzsyl72ysbfc1g-compiler-rt-5.0.2-dev/include -F/nix/store/7x42k0scp8xscrf092jalvpns4cwnnj3-swift-corefoundation/Library/Frameworks
@Pitometsu
Pitometsu / cc-overlay.nix
Created September 13, 2019 05:58
How to override CC by Nix overlay?
(self: super:
let
# gcc = super.pkgs.gcc8;
# gcc8 = super.pkgs.gcc8.override { stdenv = super.stdenv; };
stdenv = super.stdenvAdapters.overrideCC super.stdenv super.pkgs.gcc8;
in
{
inherit stdenv; # gcc8 gcc;
# stdenv = super.overrideCC super.stdenv self.pkgs.gcc;
# gcc8 = super.gcc8.override { stdenv = super.stdenv; };
@Pitometsu
Pitometsu / m.ml
Created August 21, 2019 17:40
first-class modules type limitation
utop # let (module M) = (module Caml.Map.Make(Int64) : Caml.Map.S) in let to_ : unit -> _ M.t = fun () -> failwith "und" in to_;;
Error: This expression has type unit -> 'a M.t
but an expression was expected of type 'b
The type constructor M.t would escape its scope
utop # let module M = Caml.Map.Make(Int64) in let to_ : unit -> _ M.t = fun () -> failwith "und" in to_;;
- : unit -> 'a Map.Make(Core_kernel__Int64).t = <fun>
@Pitometsu
Pitometsu / module_key.ml
Created August 21, 2019 14:29
first-class module dependent types
let f (type k) : x:((module Caml.Map.S with type key = k) as 'a) -> y:'a -> z:k -> unit = fun ~x:(_) ~y:(_) ~z:(_) -> ();;
val f :
x:(module Core.Caml.Map.S with type key = 'a) ->
y:(module Core.Caml.Map.S with type key = 'a) -> z:'a -> unit = <fun>
@Pitometsu
Pitometsu / depth.ml
Last active August 15, 2019 02:40
First-class modules sub-typing
module type C = sig type 'a t = [>`C|`D] as 'a end
module type D = sig include C with type 'a t = [>`D] as 'a end
module rec C : C = C;;
module rec D : D = D;;
type c_t = (module C);;
type d_t = (module D);;
(fun (m : c_t) -> (m :> d_t)) (module C);;
- : d_t = <module>
@Pitometsu
Pitometsu / m.ml
Created August 13, 2019 20:15
Pass module's existential type to universal argument
module type S = sig
type t
val of_string : string -> t
val to_string : t -> string
end
let deser : 'a. (module S with type t = 'a) -> (_ -> 'a) * _ = fun m ->
let module M = (val m) in
@Pitometsu
Pitometsu / constraint.ml
Created July 29, 2019 12:36
question about constraint syntax
utop # type t = unit -> (string, string, 'a) Map.t option constraint 'a = String.comparator_witness;;
type t = unit -> (string, string, String.comparator_witness) Map.t option
utop # let f : 'a. unit -> (string, string, 'a) Map.t option constraint 'a = String.comparator_witness = fun () -> failwith "hello";;
Error: Syntax error
utop # let f : unit -> (string, string, 'a) Map.t option constraint 'a = String.comparator_witness = fun () -> failwith "hello";;
Error: Syntax error
@Pitometsu
Pitometsu / imagex.nix
Last active July 21, 2019 03:41
Nix /home to docker installation problem
mypkg = mkDerivation rec {
name = "mypkg";
version = "0.0.1";
src = ./.;
# ...
outputs = [ "out" "custom" ];
installPhase = ''
mkdir -p $out
do-some-install-to $out
mkdir -pv $custom/share
@Pitometsu
Pitometsu / configure
Created July 10, 2019 06:48
https://github.com/jhjourdan/ocaml/archive/memprof_4.05.0.tar.gz | configure flags: -prefix /nix/store/r93bflfbwbx0azzpb31dydlc0ibqxvlx-ocaml+flambda+spacetime-4.05.0 -x11lib /nix/store/3fqq1jb9acjlidhs34h2llsic31xh6r2-x11env/lib -x11include /nix/store/3fqq1jb9acjlidhs34h2llsic31xh6r2-x11env/include -flambda -with-debug-runtime --statmemprof -wi…
In file included from caml/custom.h:23:0,
from minor_gc.c:19:
minor_gc.c: In function 'alloc_shr_minor':
minor_gc.c:189:54: error: 'old_header' undeclared (first use in this function); did you mean 'Make_header'?
CAML_ALLOC_EFFECT_NONE, Profinfo_hd(old_header));
^
caml/mlvalues.h:120:40: note: in definition of macro 'Profinfo_hd'
#define Profinfo_hd(hd) (((mlsize_t) ((hd) >> PROFINFO_SHIFT)) & PROFINFO_MASK)
^~
minor_gc.c:189:54: note: each undeclared identifier is reported only once for each function it appears in