Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Different ByteStrings, what now? (Daniel Fischer)
   2.  Data declarations (Christopher Howard)
   3.  question regarding standard libraries (Jake Penton)
   4. Re:  Data declarations (Antoine Latter)
   5. Re:  question regarding standard libraries (Antoine Latter)
   6. Re:  Data declarations (aditya siram)
   7. Re:  question regarding standard libraries (Jake Penton)
   8. Re:  Data declarations (Christopher Howard)


----------------------------------------------------------------------

Message: 1
Date: Thu, 2 Jun 2011 17:14:21 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Different ByteStrings, what now?
To: Raphael P?bst <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="iso-8859-1"

On Thursday 02 June 2011 15:46:14, Raphael P?bst wrote:
> Ah thanks, that's it. I know about ByteString and ByteString.Lazy, but
> the error message confused me, since it said it was expecting
> Text.ProtocolBuffers.Header.ByteString of which I had never heard
> before.
> 
> Raf

Yes, that's quite understandable.

How GHC prints types in error messages depends (in a non-obvious way, 
unfortunately) on the way in which they were imported.
Often that's helpful (Explicitly.Imported.Module.Type vs. 
Some.Very.Well.Hidden.Module.Never.Heard.Of.Type), but sometimes it leads 
to confusing results (as here).



------------------------------

Message: 2
Date: Thu, 02 Jun 2011 19:03:49 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] Data declarations
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I'm trying to understand the Haskell type system, because it is
portrayed as a rather powerful tool when properly harnessed. There are a
few things, however, I could use some clarification on. For starters,
I'm a bit confused about the "data" declarations:

I understand (correctly, I hope) that the purpose of a "data"
declaration is to create a new type. So this makes sense:

data KeyValuePair = KeyValuePair String String

However, this also compiles:

data KeyValuePair a b = KeyValuePair String String

As well as does this:

data KeyValuePair a b = KeyValuePair String

And this:

data KeyValuePair a b = KeyValuePair

So you can see how I'm getting a bit confused?

-- 
frigidcode.com
theologia.indicium.us



------------------------------

Message: 3
Date: Thu, 2 Jun 2011 23:23:30 -0400
From: Jake Penton <[email protected]>
Subject: [Haskell-beginners] question regarding standard libraries
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

I have a couple of questions about "standard libraries" as referred to in the 
Haskell 98 and 2010 reports.

First, is there anything to infer from the use of the term "libraries"? What I 
see documented in the reports is a set of modules. Is this just a loose usage 
of the term libraries to mean a set of modules implemented somehow or other?

Second, although I have only perused the 98 and 2010 reports briefly, what 
"standard" means in this context does not stand out for me. Part II of the 2010 
report jumps right into the description of Control.Monad with no mention of the 
relationship of Part II to the rest of the report. Are the documented modules 
part of the language?

Third, as I am learning Haskell by studying Real World Haskell I note that 
several of the modules discussed therein are not listed in the Haskell 2010 
report. A notable example is Data.Map. What is the status of such modules? Are 
they just (maybe) available in particular implementations, or in privately 
donated packages? 

Finally, is there a good way to track changes in the implementation of various 
modules, whether "standard" or otherwise? For example I discover that 
Data.Map.lookup has changed (in ghc anyway) since RWH was written. Is this 
change agreed upon somewhere, or is it just dependent on whatever happens to be 
delivered with the Haskell implementation that I use?

Thank heaven for a beginner's mailing list where I can ask dumb questions. And 
thanks in advance once again for your kind efforts to help me out.

- J -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110602/ddb41228/attachment-0001.htm>

------------------------------

Message: 4
Date: Thu, 2 Jun 2011 22:39:18 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Data declarations
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Thu, Jun 2, 2011 at 10:03 PM, Christopher Howard
<[email protected]> wrote:
> I'm trying to understand the Haskell type system, because it is
> portrayed as a rather powerful tool when properly harnessed. There are a
> few things, however, I could use some clarification on. For starters,
> I'm a bit confused about the "data" declarations:
>
> I understand (correctly, I hope) that the purpose of a "data"
> declaration is to create a new type. So this makes sense:
>
> data KeyValuePair = KeyValuePair String String
>
> However, this also compiles:
>
> data KeyValuePair a b = KeyValuePair String String
>
> As well as does this:
>
> data KeyValuePair a b = KeyValuePair String
>
> And this:
>
> data KeyValuePair a b = KeyValuePair
>
> So you can see how I'm getting a bit confused?
>

Yes, 'data' declarations are for introducing a new type.

Keep in mind that the type parameters (here 'a' and 'b') are not
fundamental to the process - I can also declare

> data MyType = MT Integer String

Maybe I can continue the discussion with a question:

* Why should the above examples not compile?

Then we can more deeply explore your confusion :-)

Antoine

> --
> frigidcode.com
> theologia.indicium.us
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



------------------------------

Message: 5
Date: Thu, 2 Jun 2011 22:56:38 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] question regarding standard libraries
To: Jake Penton <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Thu, Jun 2, 2011 at 10:23 PM, Jake Penton <[email protected]> wrote:
> I have a couple of questions about "standard libraries" as referred to in
> the Haskell 98 and 2010 reports.
> First, is there anything to infer from the use of the term "libraries"? What
> I see documented in the reports is a set of modules.?Is this just a loose
> usage of the term libraries to mean a set of modules implemented somehow or
> other?

I don't think that the report provides a definition of the term
'library'. As far as I know, your 'collection of modules' is a good
definition.

> Second, although I have only perused the 98 and 2010 reports briefly, what
> "standard" means in this context does not stand out for me. Part II of the
> 2010 report jumps right into the description of Control.Monad with no
> mention of the relationship of Part II to the rest of the report. Are the
> documented modules part of the language?

I would take 'standard' to mean 'as defined by the Haskell Language
Report'. I don't know that I would say they are part of 'the
language', which some might take to mean 'grammar and structure and
execution model'. But they do provide a minimum of functionality to
any implementation claiming to support the standard, and I would
expect a lack of any of them to be documented.

For example, here is the chapter of the GHC User's Guide describing
GHC's departure from Haskell '98, which includes references to library
functions:

http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs-and-infelicities.html#vs-Haskell-defn

> Third, as I am learning Haskell by studying Real World Haskell I note that
> several of the modules discussed therein are not?listed in the Haskell 2010
> report. A notable example is Data.Map. What is the status of such modules?
> Are they just (maybe) available in particular implementations, or in
> privately donated packages?

Data.Map is provided by the 'containers' package, available here:

http://hackage.haskell.org/package/containers

It is currently a part of the larger 'Haskell Platform', which intends
to me a living, more flexible collection of libraries than what is
enshrined by the language specification:

http://hackage.haskell.org/platform/

The website has a good description of the goals of the Haskell Platform.

> Finally, is there a good way to track changes in the implementation of
> various modules, whether "standard" or otherwise? For example I discover
> that Data.Map.lookup has changed (in ghc anyway) since RWH was written. Is
> this change agreed upon somewhere, or is it just dependent on whatever
> happens to be delivered with the Haskell implementation that I use?

For package which have a well-defined maintainer, much of this
discussion would occur with the maintainer or maintainers, with
release announcements occurring on the haskell-cafe mailing list or
occasionally the haskell announcements list. Blogs and other sites
also serve this sort of role.

The Haskell Platform itself has policies for inclusion and evolution.

Larger topics related to the state of haskell libraries takes place on
the libraries list ([email protected]). This is also a good list
for talking about the wider aims of the Haskell Platform, I suppose,
but I think they have their own list as well (altough I can't find any
links to archives or membership info).

Core packages which have no well-defined maintainer (such as the
mentioned 'containers'
are maintained via policy. Changes are proposed and discussed on the
libraries mailing list. The policy changes, and the changes are
discussed on the libraries list as well.

I'm not heavily involved in a lot of this, but I like paying
attention. So hopefully I got the details right!

Antoine


> Thank heaven for a beginner's mailing list where I can ask dumb questions.
> And thanks in advance once again for your kind efforts to help me out.
> - J -
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>



------------------------------

Message: 6
Date: Thu, 2 Jun 2011 22:58:10 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Data declarations
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

> data KeyValuePair a b = KeyValuePair String String

'a' and 'b' are called phantom types and they are used to tag a
datatype. Rather than explain what that means in some abstract way
I'll just show you how I have used them:

I had the following simple program that retrieved values from and
wrote to a dictionary data structure (like Oxford's or Webster's).
Here are the types in Haskell:
type Name = String
type Definition = String
type Dictionary = [(Name,Definition)]

The actual contents of the dictionary were stored in a SQLite database
so I needed to read them into the "Dictionary" type whenever I started
up the program.

And I had a number of functions that queried the "Dictionary" that
required on a populated dictionary and I wanted to check *at compile
time* that they would only be called on a populated dictionary. So I
added the following two datatypes:
data Populated = Populated
data New = New

I then changed my "Dictionary" to take an extra argument that is never
used just like your "KeyValuePair":
type Dictionary a = [(Name,Definition)]

Now I could write a function that populated the dictionary:
populateFromDatabase :: Dictionary New -> IO (Dictionary Populated)

and query functions:
getDefinition :: Name -> Dictionary Populated -> Definition

Since "populateFromDatabase" is the only function that can create a
"Dictionary Populated" the phantom type statically guarantees that
"getDefinition" and any other function that expects a full dictionary
can never be called before "populateFromDatabase".

The Haskell Wiki has a similar example [1] and Richard Jones has a
nice article on they are used in Ocaml [2] .

hth,
-deech

[1] http://www.haskell.org/haskellwiki/Phantom_type
[2] http://camltastic.blogspot.com/2008/05/phantom-types.html



------------------------------

Message: 7
Date: Fri, 3 Jun 2011 00:23:25 -0400
From: Jake Penton <[email protected]>
Subject: Re: [Haskell-beginners] question regarding standard libraries
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


Thanks Antoine. That answers my questions very well.

I get fairly easily confused about the relationship between various pieces of 
the Haskell ecosystem, i.e. what's part of the language, what is specific to an 
implementation, etc.  So your answer helps me in this respect.

Best,

- Jake -




------------------------------

Message: 8
Date: Thu, 02 Jun 2011 21:10:01 -0800
From: Christopher Howard <[email protected]>
Subject: Re: [Haskell-beginners] Data declarations
To: aditya siram <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 06/02/2011 07:58 PM, aditya siram wrote:
>> data KeyValuePair a b = KeyValuePair String String
> 
> 'a' and 'b' are called phantom types and they are used to tag a
> datatype. Rather than explain what that means in some abstract way
> I'll just show you how I have used them:
> 
> I had the following simple program that retrieved values from and
> wrote to a dictionary data structure (like Oxford's or Webster's).
> Here are the types in Haskell:
> type Name = String
> type Definition = String
> type Dictionary = [(Name,Definition)]
> 
> The actual contents of the dictionary were stored in a SQLite database
> so I needed to read them into the "Dictionary" type whenever I started
> up the program.
> 
> And I had a number of functions that queried the "Dictionary" that
> required on a populated dictionary and I wanted to check *at compile
> time* that they would only be called on a populated dictionary. So I
> added the following two datatypes:
> data Populated = Populated
> data New = New
> 
> I then changed my "Dictionary" to take an extra argument that is never
> used just like your "KeyValuePair":
> type Dictionary a = [(Name,Definition)]
> 
> Now I could write a function that populated the dictionary:
> populateFromDatabase :: Dictionary New -> IO (Dictionary Populated)
> 
> and query functions:
> getDefinition :: Name -> Dictionary Populated -> Definition
> 
> Since "populateFromDatabase" is the only function that can create a
> "Dictionary Populated" the phantom type statically guarantees that
> "getDefinition" and any other function that expects a full dictionary
> can never be called before "populateFromDatabase".
> 
> The Haskell Wiki has a similar example [1] and Richard Jones has a
> nice article on they are used in Ocaml [2] .
> 
> hth,
> -deech
> 
> [1] http://www.haskell.org/haskellwiki/Phantom_type
> [2] http://camltastic.blogspot.com/2008/05/phantom-types.html
> 

Thank you. The first reference link was especially helpful in explaining
phantom types.

One more question, out of curiosity: In your above example, you could change

  data Populated = Populated
  data New = New

to simply

  data Populated
  data New

correct? You might as well, right, since your constructors take no
values, and you are just using them as phantom types?

-- 
frigidcode.com
theologia.indicium.us



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 36, Issue 6
****************************************

Reply via email to