Smap
SmapIE
New program
Curry
Prolog
Haskell
Open program by ID
Browser
Dashboard
Programs on Smap
Most recent
Most favorited
Tags on Smap
All tags
Sign in
Help
Source code
Language:
Curry
-- Examples for higher-order functions in Curry. -- Basically, these are identical to Haskell and -- already predefined in the Orelude. -- Apply a function to all list elements (predefined as `map'): map _ [] = [] map f (x:xs) = f x : map f xs -- Accumulate all list elements (predefined as `foldr'): foldr _ z [] = z foldr f z (h:t) = f h (foldr f z t) inc x = x+1 -- increment function goal1 = map inc [0,2,1] -- increment list elements goal2 = map (+ 1) [0,2,1] -- increment list elements goal3 = foldr (+) 0 [1,0,2] -- sum of all list elements goal4 = foldr (*) 1 [1,2,3,4,5] -- product of all list elements -- Main expression to be evaluated: main = goal4
Execution result
No execution result yet.
PAKCS 3.7 /all-values
PAKCS 3.7 /one-value
KiCS2 3.1 /all-values
KiCS2 3.1 /one-value
Reset
Clear
Options
New Curry program
Reload program 16
View in Browser
Program ID:
16
Title:
Higher-order functions
Language:
Curry
Author:
mh
Version:
1
Program information