Comparisment

   - compare programming languages by example

31

Function definition

Define functions that take arguments and produce a result.

Created by sam

Add a new answer

Either add an answer for a new language or add an alternative solution.
A description is only necessary when the code is not suitably 'obvious' or to justify an alternative approach.

Haskell

isEven :: Int -> Bool
isEven i = i % 2 == 0

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Haskell

add :: Int -> (Int -> Int)
add x y = x + y

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Haskell

add :: Int -> Int -> Int
add x y = x + y

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Haskell

add :: Int -> Int -> Int
add = \x -> \y -> x + y

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Haskell

add :: Int -> Int -> Int
add = \x y -> x + y

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Haskell

add :: Int -> Int -> Int
add = (+)

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Haskell

add :: Int -> Int -> Int
add x 0 = x
add x n | n > 0     = add (x+1) (n-1)
        | otherwise = add (x-1) (n+1) 

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Python

def add(x, y): return (x + y)

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.