1
1
mirror of https://github.com/tweag/nickel.git synced 2024-09-21 00:19:57 +03:00
nickel/examples/polymorphism
Yann Hamdaoui 5d1b6a840a
Update README.md
Fix typos
2021-09-14 15:07:14 +02:00
..
polymorphism.ncl Put each example in its own directory with a README 2021-04-28 18:37:11 +02:00
README.md Update README.md 2021-09-14 15:07:14 +02:00

Polymorphism

This example shows the usage of (statically typed) polymorphism in Nickel through forall. Polymorphic functions are the ones operating on generic values. Polymorphic types can be nested in Nickel, although it is rarely needed. Note that they must always be written explicitly: the typechecker never infers polymorphic types for you.

Run

$ nickel -f polymorphism.ncl

Playground

Try to swap some type variables, or to mess with the definition of the functions to see the program failing to typecheck.