Comparisment

   - compare programming languages by example

9

Subtraction

Subtract two 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

subtract :: Int -> Int -> Int
subtract x y = x - y

'-' is the infix subtraction 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

subtract :: Num a => a -> a -> a
subtract x y = x - y

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

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Python

def subtract(x, y): return x - y

- is the infix subtraction operator.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.