Comparisment

   - compare programming languages by example

8

Addition

Addition of numbers.

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

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

'+' is the infix addition operator between two arguments of type "Num a => a" of which "Int" is a defined instance.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Haskell

add :: Num a => a -> a -> a
add x y = x + y

Any instance of the "Num" typeclass can be added.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Python

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

"+" is the infix addition operator.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.