tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

58 lignes · 1498 octetsBrut · Historique
1// Import ergonomics (issue #297): a local named like an imported module
2// shadows it (W0101) and the failing `local.item` access says so, and an
3// import nothing uses is drift (W0102).
4
5import std/dict as d
6import std/http/cookie //~ WARN W0102 never used
7import std/io
8import std/list
9import std/option.{is_some}
10import std/random //~ WARN W0102 never used
11import std/string.{repeat} //~ WARN W0102 never used
12import std/time
13
14// A parameter named like an imported module shadows it; the field access
15// that follows fails, with a note pointing at the parameter.
16fn total ::
17 list: List<Int> //~ WARN W0101 shadows the imported module
18 -> Int
19{
20 list.length list //~ ERROR E0206 several constructors
21}
22
23// Shadowing warns even without a qualified access.
24fn head_or_zero :: list: List<Int> -> Int
25//~^ WARN W0101 shadows the imported module
26{
27 match list { [] -> 0, [x, ..] -> x }
28}
29
30// A local whose name no import bears shadows nothing; an import renamed
31// with `as` binds only its alias (`d`, not `dict`).
32fn describe :: server: String dict: d.Dict<Int, Int> -> String
33{
34 server
35}
36
37// A module used only in types and effect rows is used.
38fn with_clock :: f: fn() -> Int / <time.clock> -> Int / <time.clock>
39{
40 f ()
41}
42
43// An item imported by name and used by name: the import is used.
44fn present :: x: Option<Int> -> Bool
45{
46 is_some x
47}
48
49// The prelude needs no import.
50fn shown :: -> String
51{
52 show 1
53}
54
55pub fn main :: -> () / <io>
56{
57 io.println (show (total (list.range 1 3)))
58}