I hope this question is appropriate for this site, it's just about the choice of concrete syntax in Idris compared to Haskell, since both are very similar. I guess it's not that important, but I'm very curious about it. Idris uses =>
for some cases where Haskell uses ->
. So far I've seen that Idris only uses ->
in function types and =>
for other things like lambdas and case _ of
. Did this choice come from realizing that it's useful in practice to have a clear syntactical distinction between these use cases? Is it just an arbitrary cosmetic choice and I'm overthinking it?
2 Answers
Well, in Haskell, type signatures and values are in different namespaces, so something defined in one is at no risk of clashing with something in the other. In Idris, types and values occupy the same namespace, which is why you don't see e.g. data Foo = Foo
as you would in Haskell, but rather, data Foo = MkFoo
- the type is called Foo
, and the constructor is called MkFoo
, as there is already a value (the type Foo
), bound to the name Foo
, e.g. data Pair = MkPair
http://docs.idris-lang.org/en/latest/tutorial/typesfuns.html#tuples
So it's probably for the best it didn't try to use the arrow used to construct the type of functions, with the arrow used for lambdas - those are rather different things. You can combine them with e.g. the (Int -> Int) (\x => x)
.
I think it is because they interpret the ->
symbol differently.
From Wikipedia:
A => B
means ifA
is true thenB
is also true; ifA
is false then nothing is said aboutB
which seems right for case expressions, and
->
may mean the same as=>
, or it may have the meaning for functions given below
which is
f: X -> Y
means the functionf
maps the setX
into the setY
So my guess is that Idris just uses ->
for the narrow second meaning, i.e. for mapping one type to another in type signatures, whereas Haskell uses the broader interpretation, where it means the same as =>
.