File: lambda1.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 (36 lines) | stat: -rw-r--r-- 737 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
27
28
29
30
31
32
33
34
35
36
-- More fancy use of module-level lambdas.
-- ==
-- input { 9 } output { 3 }


module type operation = {type a type b val f: a -> b}

module compose = \(F: operation) ->
                 \(G: operation with a = F.b) -> {
  type a = F.a
  type b = G.b

  def f(x: a) = G.f (F.f x)
}

module i32_to_f64: operation with a = i32 with b = f64 = {
  type a = i32
  type b = f64
  def f(x: a) = f64.i32 x
}

module f64_to_i32: operation with a = f64 with b = i32 = {
  type a = f64
  type b = i32
  def f(x: a) = i32.f64 x
}

module f64_sqrt: operation with a = f64 with b = f64 = {
  type a = f64
  type b = f64
  def f(x: a) =  f64.sqrt x
}

module i32_sqrt = compose (compose i32_to_f64 f64_sqrt) f64_to_i32

def main(x: i32) = i32_sqrt.f x