File: function-argument2.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 (10 lines) | stat: -rw-r--r-- 307 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
-- Polymorphic higher-order function with an argument lambda that
-- closes over a local variable.
-- ==
-- input { 5 true } output { 7 }
-- input { 5 false } output { 9 }

def twice 'a (f : a -> a) (x : a) : a = f (f x)

def main (x : i32) (b : bool) : i32 =
  twice (\(y:i32) -> if b then y+1 else y+2) x