DEV Community

Anton
Anton

Posted on

7

Haskell hack: find the function you need with Hoogle.

Today I was solving a problem on Codewars. I somehow forgot about a very simple function that can check if an element is a member of a list.

Alt searching for a Haskell function

This of course led me to stackoverflow. You can find an interest hack there that was posted by AtnNn:

First find the type of the function you need.

To "Check if" means to return either True or False, a Bool.

So the function takes an Int, a list of Int (aka [Int]) and returns Bool:

Int -> [Int] -> Bool

Now ask hoogle.

elem :: Eq a => a -> [a] -> Bool

Hoogle is a very useful tool. You can integrate it with ghci.


This hack to use type signatures on Hoogle is such a wonderful thing. It makes Haskell even more intuitive.

What kind of Haskell hacks do you use?

P.S. If I remembered the function "elem" I wouldn't probably find out about that hack for a long time.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay