File: lambda2.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 (30 lines) | stat: -rw-r--r-- 717 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
-- Another clever use of module lambdas, and keyword-like application.
-- ==
-- input { 9 } output { 3.0 }


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

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

  def f(x: a) = P.G.f (P.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_sqrt: operation with a = f64 with b = f64 = {
  type a = f64
  type b = f64
  def f(x: a) =  f64.sqrt x
}

module mysqrt = compose { module F = i32_to_f64 module G = f64_sqrt }

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