Let the compiler do the work

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Let the compiler do the work

Elias Diem
Hi there

I'm referring to a post from Stefan H?ck and will quote from
there:

http://article.gmane.org/gmane.comp.lang.haskell.beginners/14198

<quote>
Now, load this into GHCi or compile with GHC. If it compiles, you're
on the right track. Now, you want to implement it using a fold
(try both, foldl and foldr):

  last5 :: [a] -> Maybe a
  last5 xs = foldr _ _ xs

The underscores are 'type holes'. This tells the compiler to give you
some information about what is supposed to be placed at the two
positions. For the moment, we are only interested in the types of the
things that go there. The compiler will tell you, that
the hole at the first position is of type

  a -> Maybe a -> Maybe a
</quote>

How does the compiler tell me this? I didn't find any flags
for GHC to turn this on. What do I miss?

--
Greetings
Elias



Reply | Threaded
Open this post in threaded view
|

Let the compiler do the work

David McBride
I believe the feature "typed holes" first came about around ghc 7.8.  I'm
not sure if there ever was a pragma for it because it got everyone so
excited it was just made to default on from its inception.

On Mon, Jan 19, 2015 at 9:29 AM, Elias Diem <lists at webconect.ch> wrote:

> Hi there
>
> I'm referring to a post from Stefan H?ck and will quote from
> there:
>
> http://article.gmane.org/gmane.comp.lang.haskell.beginners/14198
>
> <quote>
> Now, load this into GHCi or compile with GHC. If it compiles, you're
> on the right track. Now, you want to implement it using a fold
> (try both, foldl and foldr):
>
>   last5 :: [a] -> Maybe a
>   last5 xs = foldr _ _ xs
>
> The underscores are 'type holes'. This tells the compiler to give you
> some information about what is supposed to be placed at the two
> positions. For the moment, we are only interested in the types of the
> things that go there. The compiler will tell you, that
> the hole at the first position is of type
>
>   a -> Maybe a -> Maybe a
> </quote>
>
> How does the compiler tell me this? I didn't find any flags
> for GHC to turn this on. What do I miss?
>
> --
> Greetings
> Elias
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150119/ee5dc27b/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Let the compiler do the work

Elias Diem
Hi David

On 2015-01-19,  David McBride wrote:

> I believe the feature "typed holes" first came about around ghc 7.8.

Well that might explain why I can't find anything in GHC 7.4 ;-)

Thanks.

--
Greetings
Elias