Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
WASM
Zig
Javascript
GIMPLE
Ygen
ocaml source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
x86-64 ocamlopt 4.04.2
x86-64 ocamlopt 4.06.1
x86-64 ocamlopt 4.07.1
x86-64 ocamlopt 4.07.1-flambda
x86-64 ocamlopt 4.08.1
x86-64 ocamlopt 4.08.1-flambda
x86-64 ocamlopt 4.09.0
x86-64 ocamlopt 4.09.0-flambda
x86-64 ocamlopt 4.09.1
x86-64 ocamlopt 4.09.1-flambda
x86-64 ocamlopt 4.10.0
x86-64 ocamlopt 4.10.0-flambda
x86-64 ocamlopt 4.10.1
x86-64 ocamlopt 4.10.1-flambda
x86-64 ocamlopt 4.10.2
x86-64 ocamlopt 4.10.2-flambda
x86-64 ocamlopt 4.11.1
x86-64 ocamlopt 4.11.1-flambda
x86-64 ocamlopt 4.11.2
x86-64 ocamlopt 4.11.2-flambda
x86-64 ocamlopt 4.12.0
x86-64 ocamlopt 4.12.0-flambda
x86-64 ocamlopt 4.13.1
x86-64 ocamlopt 4.13.1-flambda
x86-64 ocamlopt 4.14.0
x86-64 ocamlopt 4.14.0-flambda
x86-64 ocamlopt 4.14.2
x86-64 ocamlopt 4.14.2-flambda
x86-64 ocamlopt 5.0.0
x86-64 ocamlopt 5.0.0-flambda
x86-64 ocamlopt 5.1.0
x86-64 ocamlopt 5.1.1
x86-64 ocamlopt 5.2.0
Options
Source code
module Type_equal = struct type ('a, 'b) t = T : ('a, 'a) t end module Tag = struct type 'a t = | Int of ('a, int) Type_equal.t | Bool of ('a, bool) Type_equal.t | String of ('a, string) Type_equal.t end module List_with_tag = struct type 'a t = { data : 'a list ; tag : 'a Tag.t } let maybe_append (type a b) (fst : a t) (snd : b t) : a list = match fst.tag, snd.tag with | Int T, Int T -> List.append fst.data snd.data | Bool T, Bool T -> List.append fst.data snd.data | String T, String T -> List.append fst.data snd.data | _ -> fst.data end let () = let fst : int List_with_tag.t = { tag = Int T; data = [1; 2; 3] } in let snd : int List_with_tag.t = { tag = Int T; data = [4; 5] } in print_int (List.length (List_with_tag.maybe_append fst snd))
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree