File: typeparams0.fut

package info (click to toggle)
haskell-futhark 0.25.32-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,236 kB
  • sloc: haskell: 100,484; ansic: 12,100; python: 3,440; yacc: 785; sh: 561; javascript: 558; lisp: 399; makefile: 272
file content (26 lines) | stat: -rw-r--r-- 534 bytes parent folder | download | duplicates (3)
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
-- Type-parametric type in module type.
-- ==
-- input { 1 2 } output { [1,2] }

module type MT = {
  type t 'a
  val pack [n]: [n]i32 -> t i32
  val unpack: t i32 -> []i32
}

module M0: MT = {
  type t 'a = (a,a)
  def pack (xs: []i32) = (xs[0], xs[1])
  def unpack (x: i32, y: i32) = [x,y]
}

module M1: MT = {
  type t 'a = [2]a
  def pack (xs: []i32) = [xs[0], xs[1]]
  def unpack (xs: t i32) = xs
}

def main (x: i32) (y: i32): []i32 =
  let a: M0.t i32 = M0.pack [x,y]
  let b: M1.t i32 = M1.pack (M0.unpack a)
  in M1.unpack b