How does Haskell arrange strings and when will this functionality be useful?
First, Char is an Ord instance defined by equality primitives on the base primitive Char type on the machine.
instance Ord Char where (C
then String is defined as [Char] (a Char list), and lists generally have an order if their elements have an order:
instance (Ord a) => Ord [a] where compare [] [] = EQ compare [] (_:_) = LT compare (_:_) [] = GT compare (x:xs) (y:ys) = case compare xy of EQ -> compare xs ys other -> other
and what is he. Any list whose elements are in order will in turn be ordered.
Since Char is ordered by its basic representation in the form of a bit pattern, and lists are set by ordering lists by elements, you see the behavior of String.
when will this feature be useful?
Insert rows into data structures that are polymorphic but require a sequencing method. The most noteworthy are Set and Map .
source share