File: polymorphic2.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 (16 lines) | stat: -rw-r--r-- 514 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- Polymorphic function in module parameter.
-- ==
-- input { [1,2] [true,false] }
-- output { [1,2,1,2] [true,false,true,false] [2,1] [false,true] }

module pm (P: { val frob 'a [n]: [n]a -> []a }) = {
  def frob_two 'a 'b (xs: []a) (ys: []b) = (P.frob xs, P.frob ys)
}

module double = pm { def frob 'a (xs: []a) = concat xs xs }
module reverse = pm { def frob 'a (xs: []a) = xs[::-1] }

def main (xs: []i32) (ys: []bool) =
  let (a,b) = double.frob_two xs ys
  let (c,d) = reverse.frob_two xs ys
  in (a,b,c,d)