Dynamically Typed Languages Are Not What You Think

add x y = x + y
add(x::Int64, y::Int64) = x + y

The Haskell Case

add 1 4
add 2 'c'
No instance for (Num Char) arising from a use of ‘add’
In the expression: add 2 'c'
In an equation for ‘it’: it = add 2 'c'
add :: Num a => a -> a -> a
add :: Int -> Int -> Int
add :: Int -> (Int -> Int)

The Julia Case

add(2, 'c')
ERROR: MethodError: no method matching add(::Int64, ::Char)
Closest candidates are:
add(::Int64, ::Int64) at samplecode.jl:1

Conclusion

class Dog:
def speak(self):
return "bark"
class Cat:
def speak(self):
return "meow"
>>> dog = Dog()

>>> cat = Cat()

>>> dog.speak()
'bark'

>>> cat.speak()
'meow'

>>> "animal".speak()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'speak'
'str' object has no attribute 'speak'
speak(animal::Cat) = "meow"
speak(animal::Dog) = "bark"

--

--

--

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Generate Point Cloud and Replace with Voxels Using MATLAB and SolidWorks

Alesis MIDIVerb impulses for Audio Ease Altiverb

HNG internship 8.0… Finding My Way Back

Deploy a Flutter app with Fastlane and Travis CI

Storing Git Credentials with Git Credential Helper

Julia Artifacts for Dummies

Checklist for Bug Bounty hunter based on OWASP pen-tester guide

Data Persistence with MySQL & phpMyAdmin using Docker in 3 steps

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Erik Engheim

Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

More from Medium

Coding, Knitting and War

Make a command-line game with Julia

The Beauty Of The MethodError

Swarm Robotics and its applications