Hacker News new | ask | show | jobs
by MartinMond 1106 days ago
In your example, how can the compiler (or a human) know that int is a concrete type as opposed to an unconstrained type variable?

Consider these two function signatures:

map :: ([a] -> [a])

map :: ([int] -> [int])

Furthermore the syntax that Elixir uses here let's you do something like

map :: (list(a) -> list(b))

list_to_other_data_structure :: (list(a) -> other_data_structure(a))

It all reminds me a bit of how Haskell does it https://medium.com/functional/haskell-basic-types-and-type-v...

I'm now curious to know if/how the above 'generics' would be expressed in TypeScript/Python/Go without a similar 'type constructor' syntax construct?

1 comments

A simple syntax would be something like

map :: forall a. ([a] -> [a])

or

map :: <a> ([a] -> [a])