File: polymorphic3.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 (13 lines) | stat: -rw-r--r-- 528 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
-- Polymorphic function using polymorphic type in parametric module.
-- ==
-- input { 2 3 } output { [1i64,0i64] [2.0,1.0,0.0] }

module pm (P: { type~ vector 't val reverse 't: vector t -> vector t }) = {
  def reverse_pair 'a 'b ((xs,ys): (P.vector a, P.vector b)) =
    (P.reverse xs, P.reverse ys)
}

module m = pm { type~ vector 't = ?[k].[k]t def reverse 't (xs: []t) = xs[::-1] }

def main (x: i32) (y: i32) = m.reverse_pair (iota (i64.i32 x),
                                             map f64.i64 (iota (i64.i32 y)))