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.

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

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