concept name in category haskell

appears as: name, names, names, name, The names, The name
Haskell in Depth

This is an excerpt from Manning's book Haskell in Depth.

Haskellers use the website hoogle.haskell.org to find functions by name or, even more usefully, by type annotation: for example, searching for "(Char → Bool) → Text → Text" gives the dropAround function I’ve just described, together with other functions for cleaning text.

Two values of the Student type are equal if their first fields are equal and their second fields are equal.

data Student2 m ageType = Student2 String (m ageType)

check2 :: Student2 Maybe Int -> Student2 Maybe Age
check2 = coerce
Get Programming with Haskell

This is an excerpt from Manning's book Get Programming with Haskell.

helloPerson :: String -> String
helloPerson name = "Hello" ++ " " ++ name ++ "!"

sampleMap :: Map.Map Int String
sampleMap = Map.fromList [(1,"Will")]

mainMaybe :: Maybe String
mainMaybe = do
   name <- Map.lookup 1 sampleMap
   let statement = helloPerson name
   return statement

Now suppose you have a list of names you want to sort. Here’s a set of names represented as a list of tuples.

Listing 4.4. names
names = [("Ian", "Curtis"), ("Bernard","Sumner"), ("Peter", "Hook"), ("Stephen","Morris")]

You want to sort names. Thankfully, Haskell does have a built-in sort function. To use it, you first need to import the Data.List module. To do this is fairly straightforward; you need to add the following declaration to the top of whatever file you’re working in:

import Data.List

Alternatively, you can import into GHCi. If you load a file with names and your import, you can see that Haskell’s sort takes a good guess at how to sort these tuples:

  • New York wants the name followed by a colon rather than a hyphen, for mystical reasons they won’t share.