File: function-composition.fut

package info (click to toggle)
haskell-futhark 0.25.27-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 17,836 kB
  • sloc: haskell: 99,384; ansic: 12,821; python: 3,394; yacc: 783; javascript: 558; sh: 550; lisp: 395; makefile: 263
file content (16 lines) | stat: -rw-r--r-- 467 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- Standard polymorphic function composition.
-- ==
-- input { 5 } output { true [6,6,6] [false,false,false] }
-- input { 2 } output { false [3,3,3] [true,true,true] }

def compose 'a 'b 'c (f : b -> c) (g : a -> b) (x : a) : c = f (g x)

def add1 (x : i32) : i32 = x+1
def isEven (x : i32) : bool = x % 2 == 0
def replicate3 'a (x : a) : [3]a = [x, x, x]

def main (x : i32) =
  (compose isEven add1 x,
   compose replicate3 add1 x,
   compose replicate3 isEven x
)