~mna/snow

snow/pkg/semantic/testdata/fn_generic_identity.snow -rw-r--r-- 474 bytes
424066c5Martin Angers doc: v0.0.5 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn id [$T] (v: $T) -> $T {
  return v
}

# without generic clause, invalid
fn id2(v: $T) -> $T {
  return v
}

fn main() {
  # explicit instantiation
  let s = id [string] ("a")
  let i = id [int] (1)
  printsln(s)
  printiln(i)

  # implicit instantiation, invalid for now
  let s2 = id ("b")
  let i2 = id (2)
  printsln(s2)
  printiln(i2)
}

@extern(import: "fmt", symbol: "Println")
fn printsln(s: string)

@extern(import: "fmt", symbol: "Println")
fn printiln(i: int)