Newbie Q: GHCi: Where “List” module is imported from?

Going through "Haskell. The Craft of Functional Programming" book , in section 16.8 I found a Set module example. Module declarations starts with: import List hiding (union) "Set" module here is built with list and uses among other things list comparison functions such as (==) and (<=). For example: eqSet :: Eq a => Set a -> Set a -> Bool eqSet (SetI xs) (SetI ys) = (xs == ys) Q1: Where "List" module is imported from? GHC "Base" package contains "Data.List" module, not just "List" module. Besides, "Data.List" does not have (<=) function. Q2: Any tutorial on using GHC libraries out there? Thanks! Dima

Dmitri O.Kondratiev wrote:
"Set" module here is built with list and uses among other things list comparison functions such as (==) and (<=).
Q1: Where "List" module is imported from?
GHC "Base" package contains "Data.List" module, not just "List" module.
List was the old name for it. Data.List is the new name.
Besides, "Data.List" does not have (<=) function.
Actually, lists are partly defined in the Prelude, with auxiliary functions in Data.List. In particular, <= for List is defined in the Prelude. Or rather, I should say, the Ord instance for lists is defined in the prelude (and only if the type inside the lists is itself an Ord instance). Look: Prelude> [1,2] <= [3,4] True (Lists of ints have the lexicographic ordering based on the standard ordering on integers) Prelude> [id] <= [id] <interactive>:1:5: No instance for (Ord (a -> a)) arising from use of `<=' at <interactive>:1:5-6 (Lists-of-functions aren't Ordered, because functions aren't Ordered) Jules

Jules Bean wrote:
Dmitri O.Kondratiev wrote:
"Set" module here is built with list and uses among other things list comparison functions such as (==) and (<=).
Q1: Where "List" module is imported from?
GHC "Base" package contains "Data.List" module, not just "List" module.
List was the old name for it. Data.List is the new name.
You can also use package haskell98 which gives you the original non-hierarchical standard library modules. Ben

On 2/16/07, Jules Bean
Actually, lists are partly defined in the Prelude, with auxiliary functions in Data.List. In particular, <= for List is defined in the Prelude. Or rather, I should say, the Ord instance for lists is defined in the prelude (and only if the type inside the lists is itself an Ord instance). Look:
Prelude> [1,2] <= [3,4] True
Where exactly "the Ord instance for lists is defined in the Prelude"? It seems that Prelude treats "list" as a built-in type same as a "tuple" type. Also Prelude does not know anything about Data.List type, right? As I understand in Haskell to be an instance of a class type must be declared as: instance ClassName TypeName where then declaration: instance Ord [] can be found?

On 2/16/07, Dmitri O.Kondratiev
where then declaration:
instance Ord []
can be found?
With Hugs, it can be found in /usr/lib/hugs/libraries/Hugs/Prelude.hs (on Debian anyway). For GHC, I guess it's in compiled into one of the .hi files? From Hugs' Prelude.hs: instance Ord a => Ord [a] where compare [] (_:_) = LT compare [] [] = EQ compare (_:_) [] = GT compare (x:xs) (y:ys) = primCompAux x y (compare xs ys) Aaron

Dmitri O.Kondratiev wrote:
Where exactly "the Ord instance for lists is defined in the Prelude"?
Depends slightly on your compiler, but you will find that some of the prelude has source, and some of the prelude is inevitably not written in haskell (the type system has to be bootstrapped somehow). There is special language support for lists although it is essentially just syntax: you could define a list by hand, but you wouldn't get the cute [1,2,3,4] style syntax for them (you'd have to write 1:2:3:4:Empty or similar).
It seems that Prelude treats "list" as a built-in type same as a "tuple" type. Also Prelude does not know anything about Data.List type, right?
Data.List isn't a type. It's a module. (I.e. a bunch of functions and types). Data.List just happens to define some useful functions to use on lists. http://cvs.haskell.org/Hugs/pages/libraries/base/Data-List.html
As I understand in Haskell to be an instance of a class type must be declared as:
instance ClassName TypeName
where then declaration:
instance Ord []
can be found?
In the source for the prelude. Jules
participants (4)
-
Aaron McDaid
-
Benjamin Franksen
-
Dmitri O.Kondratiev
-
Jules Bean