Skip to content
loading...

re: Something I've come to appreciate about dynamic typing VIEW POST

TOP OF THREAD FULL DISCUSSION
re: That's only a problem if a language doesn't have sum types. If we use OCaml again, with the person_info discriminated union above, it's easy to mak...

Ooh. I don't know OCaml, but that looks interesting. I guess I could probably implement something similar in Haskell.

Exactly the same principle in Haskell:

import qualified Data.Map.Strict as Map

data PersonInfo = Name String | Age Integer

m = Map.fromList [("name", Name "Baby Yoda"), ("age", Age 50)]
Map.lookup "name" m
Just (Name name) = Map.lookup "name" m
name
-- => "Baby Yoda"
code of conduct - report abuse