Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 18, 2021 02:18 pm GMT

7 Useful Tools Written in Haskell

Author: Nikolay Rulev

Introduction

Haskell is a pure functional general-purpose programming language with static typing and lazy evaluation. It was created in 1990 and was named after Haskell Curry. At present, the GHC compiler is its main implementation.

Here at Typeable we like this language very much and use it as our main language for software development. Though Haskell is already quite widely used in the industry, its still sometimes believed to be an "academical" language used exclusively for scientific purposes. In this post, Id like to tell you about several rather popular Haskell tools which may be of use to you.

Useful tools written in Haskell

1. Xmonad

Xmonad is a tile window manager for X Window System, written in Haskell. The distinctive feature of this tile manager is that its configured in Haskell, too, which allows us to use all features of the language. Thus, while configuring the window manager, you can add weather forecast data, measure the system condition, etc.

Here is an example of configured system (by erikbackman):
Xmonad screenshot by erikbackman

A config example (only a part is shown, not the entire config):

main :: IO ()main = xmonad . dynamicProjects (projects apps) . ewmh . docks . cfg =<< polybar  where    cfg dbus =      def        { manageHook = App.manageApps <+> manageSpawn,          logHook = dynamicLogWithPP (polybarHook dbus),          startupHook = myStartupHook,          terminal = fromMaybe "xterm" $ App.terminal apps,          modMask = mod4Mask,          borderWidth = 1,          keys = keybinds . KeybindConfig apps,          handleEventHook = handleEventHook def <+>            fullscreenEventHook,          layoutHook = myLayouts,          focusedBorderColor = "#bd93f9",          normalBorderColor = "#434C5E",          workspaces = myWS        }    apps =      defaultAppConfig        { App.terminal = Just "kitty",          App.launcher = Just "rofi -matching fuzzy -show drun -modi drun,run -show-icons",          App.mailClient = Just "claws-mail"        }    myStartupHook :: X ()    myStartupHook = do      setDefaultCursor xC_left_ptr

You can find further information on the xmonad website.

2. ShellCheck

ShellCheck is a utility used to analyze bash scripts. It allows novices to fish out common errors when they just start learning this scripting language and helps more advanced users not to miss small bugs in large and complex scripts. The project is being constantly expanded and its large community is adding new rules. You can view the ShellCheck and try it out at its home page.

Lets use the following script by way of example (try to find the errors in it without looking into the ShellCheck result):

#!/bin/bash## Example: ShellCheck can detect some## higher level semantic problemswhile getopts "nf:" paramdo    case "$param" in        f) file="$OPTARG" ;;        v) set -x ;;    esacdonecase "$file" in    *.gz) gzip -d "$file" ;;    *.zip) unzip "$file" ;;    *.tar.gz) tar xzf "$file" ;;    *) echo "Unknown filetype" ;;esacif [[ "$$(uname)" == "Linux" ]]then    echo "Using Linux"fi

Its very easy to check the file: shellcheck example.bash.

As the result, well be informed about all potential errors in the script:

ShecllCheck finds even higher-level semantic problems

3. PureScript

Haskell was used to develop several popular compiled functional languages for the frontend development which are eventually transpiled into JavaScript. Today were going to talk about PureScript. This language has a strict type system supporting algebraic data types, HKT (Higher-Kinded Types), and type classes with functional dependencies. It also supports several necessary and handy features such as FFI (Foreign Function Interface) with JS, and the resulting JS looks very much readable. The language has already acquired its own ecosystem: the package manager spago and IDE based on its own language server.

Below you can find the example of a simple button component written in Halogen:

module Example.Basic.Button (component) whereimport Preludeimport Halogen as Himport Halogen.HTML as HHimport Halogen.HTML.Events as HEimport Halogen.HTML.Properties as HPtype State = { enabled :: Boolean }data Action = Togglecomponent :: forall q i o m. H.Component q i o mcomponent =H.mkComponent    { initialState    , render    , eval: H.mkEval $ H.defaultEval        { handleAction = handleAction }    }initialState :: forall i. i -> StateinitialState _ = { enabled: false }render :: forall m. State -> H.ComponentHTML Action () mrender state =let    label = if state.enabled then "On" else "Off"in    HH.button    [ HP.title label    , HE.onClick \_ -> Toggle    ]    [ HH.text label ]handleAction :: forall o m. Action  -> H.HalogenM State Action () o m UnithandleAction = case _ ofToggle ->    H.modify_ \st -> st { enabled = not st.enabled }

For further study, you can proceed to the official website.

4. Agda

Haskell works really well when it comes to developing programming languages! Agda is another example. This is a language with a strong theoretical background and dependent types whose syntax looks much like that of Haskell. Moreover, this is also an automated theorem proving system: logical assertions are expressed as types, and successful type checking is the proof of program correctness.

What's this all for? First of all, this allows avoiding a vast number of run-time errors and to some extent prevents the programmer from writing incorrect code, as utopian as it may sound. Lets consider a classic example: wed like to rewrite the head function that takes the list head but we want to make sure that we dont pass an empty list to this function anywhere in our program.

-- Natural numbers in the form of-- Peano numbers and their additiondata Nat : Set where  zero : Nat  suc  : Nat -> Nat_+_ : Nat -> Nat -> Nat zero  + m = m suc n + m = suc (n + m)-- Vector, dependent type whose length-- is stored in the typedata Vec (A : Set) : Nat -> Set where  []   : Vec A zero  _::_ : {n : Nat} -> A -> Vec A n -> Vec A (suc n)-- head that cannot be applied to an empty vectorhead : {A : Set}{n : Nat} -> Vec A (suc n) -> Ahead (x :: xs) = x

5. PostgREST

PostgREST is an independent web server that will turn your database schema directly into RESTful API. This approach saves you the trouble of writing the boilerplate for CRUD and allows you to focus on the important details of business logic. The advantages include the use of PostgreSQL binary protocol and serialization of JSON directly to SQL to improve performance.

Lets take a simple city and country scheme as an example:
PostgREST takes your database schema...

As the result, we get the following API for this scheme:
...and converts it into API

Documentation is here.

6. Octopod

Octopod is a service we developed in Typeable that allows our team to use the entire Helms potential without the need for technical knowledge. Our solution makes it easier to manage dynamic environments for the whole team: DevOps, developers, testers, and project managers. All you need is to indicate the URL to the Helm repository and Octopod will automatically get the required configurations.

We wrote about this service earlier, and you can find more information on Octopod home page.

7. Pandoc

Pandoc is a multitool that allows converting data in one text format into a totally different format. The utility understands a lot of useful syntax extensions, including the document metadata: author, heading, dates, footnotes, tables, highlighting of code snippets, LaTex inserts with formulas, etc. Supported document formats include Markdown, epub, docs, RTF, ODT, HTML, LaTeX, various formats of wiki markdown and bibliography.

You can download the tool and view all supported formats here.

I didnt list all supported conversion options as it wouldve taken all the post. Just look at the graph showing what and how can be converted:
a big picture!

Conclusion

Here Ive listed the open-source projects which I believe to be the most interesting and useful for a wide circle of users. This list can be used as an answer to the question Is there anything useful written in Haskell beyond the science?

Surely, the list is not exhaustive and can be extended. If you think that it should include a certain project or just want to share a cool Haskell tool let us know and leave a comment!


Original Link: https://dev.to/typeable/7-useful-tools-written-in-haskell-560d

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To