Exercism v3 launches on Sept 1st 2021. Learn more! 🚀🚀🚀
Avatar of nicolemon

nicolemon's solution

to Pangram in the Haskell Track

Published at Jul 18 2018 · 0 comments
Test suite


This exercise has changed since this solution was written.

Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:

The quick brown fox jumps over the lazy dog.

The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input will not contain non-ASCII symbols.

Getting Started

For installation and learning resources, refer to the exercism help page.

Running the tests

To run the test suite, execute the following command:

stack test

If you get an error message like this...

No .cabal file found in directory

You are probably running an old stack version and need to upgrade it.

Otherwise, if you get an error message like this...

No compiler found, expected minor version match with...
Try running "stack setup" to install the correct GHC...

Just do as it says and it will download and install the correct compiler version:

stack setup

Running GHCi

If you want to play with your solution in GHCi, just run the command:

stack ghci

Feedback, Issues, Pull Requests

The exercism/haskell repository on GitHub is the home for all of the Haskell exercises.

If you have feedback about an exercise, or want to help implementing a new one, head over there and create an issue. We'll do our best to help you!


Wikipedia https://en.wikipedia.org/wiki/Pangram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


{-# LANGUAGE RecordWildCards #-}

import Data.Foldable     (for_)
import Test.Hspec        (Spec, describe, it, shouldBe)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

import Pangram (isPangram)

main :: IO ()
main = hspecWith defaultConfig {configFastFail = True} specs

specs :: Spec
specs = describe "isPangram" $ for_ cases test
    test Case{..} = it description $ isPangram input `shouldBe` expected

data Case = Case { description :: String
                 , input       :: String
                 , expected    :: Bool

cases :: [Case]
cases = [ Case { description = "sentence empty"
               , input       = ""
               , expected    = False
        , Case { description = "recognizes a perfect lower case pangram"
               , input       = "abcdefghijklmnopqrstuvwxyz"
               , expected    = True
        , Case { description = "pangram with only lower case"
               , input       = "the quick brown fox jumps over the lazy dog"
               , expected    = True
        , Case { description = "missing character 'x'"
               , input       = "a quick movement of the enemy will jeopardize five gunboats"
               , expected    = False
        , Case { description = "another missing character, e.g. 'h'"
               , input       = "five boxing wizards jump quickly at it"
               , expected    = False
        , Case { description = "pangram with underscores"
               , input       = "the_quick_brown_fox_jumps_over_the_lazy_dog"
               , expected    = True
        , Case { description = "pangram with numbers"
               , input       = "the 1 quick brown fox jumps over the 2 lazy dogs"
               , expected    = True
        , Case { description = "missing letters replaced by numbers"
               , input       = "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"
               , expected    = False
        , Case { description = "pangram with mixed case and punctuation"
               , input       = "\"Five quacking Zephyrs jolt my wax bed.\""
               , expected    = True
        , Case { description = "upper and lower case versions of the same character should not be counted separately"
               , input       = "the quick brown fox jumps over with lazy FX"
               , expected    = False
module Pangram (isPangram) where

import Data.Char (toLower)

-- make string all lowercase
toLower' :: String -> String
toLower' s = [toLower c | c <- s]

-- check for membership of each lowercase letter in text
isPangram :: String -> Bool
isPangram text = all (`elem` toLower' text) ['a'..'z']

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?