This page shows side by side 'translations' of code written in two given
programming languages to solve the same problem.
This could be useful for learning a new programming language by comparison to a familiar one.
This page is currently a simple view into the data created on the primary comparisons page and is even more beta.
1 2 :: Num a => a 3 :: Int
Numeric literals may be used to represent "Int" values. Their type however is more general "Num a => a", meaning the same syntax may be used for any other instance of the Num typeclass such as Float, Double, etc. When ambiguous, a type signature can be given with ":: Int" to specialise the type. Numeric literals have special type defaulting rules meaning that if the type is ambigous then the type is first taken as "Int", and second as "Double". These rules can be overiden by making a "default" declaration.
greeting = "Hello World!"
A string is enclosed in double quotation marks.
greeting = 'Hello World!'
A string may be enclosed in single quotation marks.
def add(x, y): return x + y
"+" is the infix addition operator.
def subtract(x, y): return x - y
- is the infix subtraction operator.
def multiply(x, y): return x * y
* is the infix multiplication operator.
multiply :: Int -> Int -> Int multiply x y = x * y
'*' is the infix multiplication operator between two arguments of type "Num a => a" of which "Int" is a defined instance.
multiply :: Num a => a -> a -> a multiply x y = x * y
Any instance of the "Num" typeclass can be multiplied together.