Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't GHCi allow type arguments for this version of join?

Tags:

types

haskell

I've tried toying around with TypeApplications, and used the following:

 join = (>>= id)
 :t join
join :: Monad m => m (m a) -> m a
 :t join @[]

But I get the following error:

<interactive>:1:1: error:
    * Cannot apply expression of type `m0 (m0 b0) -> m0 b0'
      to a visible type argument `[]'
    * In the expression: join @[]

This, in my view, should work, as

 :t fmap @[]
fmap @[] :: (a -> b) -> [a] -> [b]

works.

like image 588
schuelermine Avatar asked Nov 01 '18 17:11

schuelermine


1 Answers

Type applications only work for definitions that have explicit type signatures.

>>> join :: (Monad m) => m (m a) -> m a; join = (>>= id)
>>> :t join @[]
join @[] :: [[a]] -> [a]

All the gory details (and there are quite a few) of this extension are in the paper Visible Type Application.

like image 96
luqui Avatar answered Oct 20 '22 18:10

luqui