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. String type hello-o-matic... (Emacs The Viking)
2. Re: String type hello-o-matic... (David McBride)
3. Re: String type hello-o-matic... (David McBride)
4. Re: String type hello-o-matic... (Antoine Latter)
5. tuple update (Ovidiu Deac)
6. Re: tuple update (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Fri, 09 Mar 2012 15:01:00 +0000
From: Emacs The Viking <[email protected]>
Subject: [Haskell-beginners] String type hello-o-matic...
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaagh!
Ok, that said, now I can explain my self a little more clearly.
I am
almost to the point of exasperation on trying to know when and why and
how to convert between String, ByteString, ByteString.Laz, Char8 etc.
For heavens sake how many bloody string types can you need? LOL
I am
trying to use Data.Digest.Pure.SHA but it takes a ByteString in the
"sha1" function but from the command prompt of ghci I cannot seem to
work out how to do it, I just get the usual daunting messages.
sha1
:: ByteString -> Digest SHA1State
I have a String, but the pack
function wants a [Word8] to create a digest value.
pack :: [Word8] ->
ByteString
IIUC, String is just [Char] and that Char is in fact a
Unicode character and therefore NOT "8 bit" as such which is why the
Char8 variants exist. I understand the difference between lazy and
strict and why one is different from the other. But... it's little
things like the foldr' function NOT being present in one library but
present in the other, presumably a lazy implementation doesn't need a
strict function or something like that. Who knows. I don't!
I am sure
to "seasoned" haskellers this is all elementary and I would love to
eventually become a seasoned developer of it too but at times like this
I want to scream in utter confusion as to how many different string
types there are and the sometimes almost unnotcable differences between
them. And trying to convert between them to actually get on and write
useful working code.
When do I use strict? When do I use lazy? When do
I use the Char8 variant? And so the questions continue with barely any
"beginner" level answers to be found. I'd write them myself but I don't
know the answers yet!
Speaking as a non-academic, non-mathemetician,
but as a developer with 25+ years of using lots of languages inclusing
Erlang, LISP and Scala, sometimes Haskell is very very hard to
perservere with because everybody just seems to love using words and
phrases like "mono-morphism", "monadic transformers" etc. just to show
off how well they understand Haskell. That's fine for those in the club
but those on the outside looking in would also like to be able to "get
in" as well and be able to write serious looking blog posts about how
damned funky haskell is.
And it is... but not if you can't understand
it! is there some kind of Free Masonry involved ;)
Thanks again,
Sean... now where's my RWH book again...
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120309/0b47c1d7/attachment-0001.htm>
------------------------------
Message: 2
Date: Fri, 9 Mar 2012 11:47:32 -0500
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] String type hello-o-matic...
To: Emacs The Viking <[email protected]>
Cc: [email protected]
Message-ID:
<CAN+Tr42BZv=5tmubjstmsd1a5sp_brc8v66tvnqaeabxkr0...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
It seems a little confusing at first, but it's not so bad once you
learn a few things.
For your initial question, if you import Data.ByteString, you'll end
up with Word8 in all of the functions, including pack. Just import
Data.ByteString.Char8. It is just like the other import, but all the
functions use Chars instead of Word8's.
There are only three important data types.
String, which is a list of char, simple, slow, memory inefficient, but
easy to work with.
ByteString which is just for binary data. Each index is 8 bits, and
it is efficient for memory and it is one big block of data.
Text is almost like bytestring, except that it is designed with text
encoding in mind. It is like a middle ground between bytestring and
string, with very good performance, but without throwing away
important info about characters.
Both ByteString and Text have variants, strict and lazy. If you look
at what they are actually composed of, you'll see that all it is, is
that instead of having one big block, the lazy variant is like a
linked list of blocks. That way, you can have it in memory, replace
some text within it, append to it, etc., without having to reallocate
the entire thing every single time you change a character.
To get strings into Text, there are libraries on hackage that involve
encoding and decoding things. Once you get the hang of it, the only
other thing you might need to know is how builders work. All that
does is try to get the chunks of the lazy variants to have uniform
size, more or less. But that is for a future date, when you are
writing something that needs to be super duper efficient.
On Fri, Mar 9, 2012 at 10:01 AM, Emacs The Viking <[email protected]> wrote:
> Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaagh!
>
> Ok, that said, now I can explain my self a little more clearly.
>
> I am almost to the point of exasperation on trying to know when and why and
> how to convert between String, ByteString, ByteString.Laz, Char8 etc. For
> heavens sake how many bloody string types can you need? LOL
>
> I am trying to use Data.Digest.Pure.SHA but it takes a ByteString in the
> "sha1" function but from the command prompt of ghci I cannot seem to work
> out how to do it, I just get the usual daunting messages.
>
> ? ? sha1 :: ByteString -> Digest SHA1State
>
> I have a String, but the pack function wants a [Word8] to create a digest
> value.
>
> ? ? pack :: [Word8] -> ByteString
>
> IIUC, String is just [Char] and that Char is in fact a Unicode character and
> therefore NOT "8 bit" as such which is why the Char8 variants exist. I
> understand the difference between lazy and strict and why one is different
> from the other. But... it's little things like the foldr' function NOT being
> present in one library but present in the other, presumably a lazy
> implementation doesn't need a strict function or something like that. Who
> knows. I don't!
>
> I am sure to "seasoned" haskellers this is all elementary and I would love
> to eventually become a seasoned developer of it too but at times like this I
> want to scream in utter confusion as to how many different string types
> there are and the sometimes almost unnotcable differences between them. And
> trying to convert between them to actually get on and write useful working
> code.
>
> When do I use strict? When do I use lazy? When do I use the Char8 variant?
> And so the questions continue with barely any "beginner" level answers to be
> found. I'd write them myself but I don't know the answers yet!
>
> Speaking as a non-academic, non-mathemetician, but as a developer with 25+
> years of using lots of languages inclusing Erlang, LISP and Scala, sometimes
> Haskell is very very hard to perservere with because everybody just seems to
> love using words and phrases like "mono-morphism", "monadic transformers"
> etc. just to show off how well they understand Haskell. That's fine for
> those in the club but those on the outside looking in would also like to be
> able to "get in" as well and be able to write serious looking blog posts
> about how damned funky haskell is.
>
> And it is... but not if you can't understand it! is there some kind of Free
> Masonry involved ;)
>
> Thanks again,
>
> Sean... now where's my RWH book again...
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 3
Date: Fri, 9 Mar 2012 11:56:31 -0500
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] String type hello-o-matic...
To: Emacs The Viking <[email protected]>
Cc: [email protected]
Message-ID:
<can+tr41vodn0pbrjrkunfuc222deme1zkqlkektqsmrugwt...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Oh, and one other thing. There is an OverloadedStrings extension.
You can enable it with ghci -XOverloadedStrings, or put a language
pragma at the top of your source file. This allows you to just type
strings and the compiler will infer them as Istring a => a, where all
of the above types are instances of it. This means you can type
Data.Bytestring.PutStrLn "hello world" and it will convert the string
into bytestring when you compile.
On Fri, Mar 9, 2012 at 11:47 AM, David McBride <[email protected]> wrote:
> It seems a little confusing at first, but it's not so bad once you
> learn a few things.
>
> For your initial question, if you import Data.ByteString, you'll end
> up with Word8 in all of the functions, including pack. ?Just import
> Data.ByteString.Char8. ?It is just like the other import, but all the
> functions use Chars instead of Word8's.
>
> There are only three important data types.
>
> String, which is a list of char, simple, slow, memory inefficient, but
> easy to work with.
> ByteString which is just for binary data. ?Each index is 8 bits, and
> it is efficient for memory and it is one big block of data.
> Text is almost like bytestring, except that it is designed with text
> encoding in mind. ?It is like a middle ground between bytestring and
> string, with very good performance, but without throwing away
> important info about characters.
>
> Both ByteString and Text have variants, strict and lazy. ?If you look
> at what they are actually composed of, you'll see that all it is, is
> that instead of having one big block, the lazy variant is like a
> linked list of blocks. ?That way, you can have it in memory, replace
> some text within it, append to it, etc., without having to reallocate
> the entire thing every single time you change a character.
>
> To get strings into Text, there are libraries on hackage that involve
> encoding and decoding things. ?Once you get the hang of it, the only
> other thing you might need to know is how builders work. ?All that
> does is try to get the chunks of the lazy variants to have uniform
> size, more or less. ?But that is for a future date, when you are
> writing something that needs to be super duper efficient.
>
>
> On Fri, Mar 9, 2012 at 10:01 AM, Emacs The Viking <[email protected]> wrote:
>> Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaagh!
>>
>> Ok, that said, now I can explain my self a little more clearly.
>>
>> I am almost to the point of exasperation on trying to know when and why and
>> how to convert between String, ByteString, ByteString.Laz, Char8 etc. For
>> heavens sake how many bloody string types can you need? LOL
>>
>> I am trying to use Data.Digest.Pure.SHA but it takes a ByteString in the
>> "sha1" function but from the command prompt of ghci I cannot seem to work
>> out how to do it, I just get the usual daunting messages.
>>
>> ? ? sha1 :: ByteString -> Digest SHA1State
>>
>> I have a String, but the pack function wants a [Word8] to create a digest
>> value.
>>
>> ? ? pack :: [Word8] -> ByteString
>>
>> IIUC, String is just [Char] and that Char is in fact a Unicode character and
>> therefore NOT "8 bit" as such which is why the Char8 variants exist. I
>> understand the difference between lazy and strict and why one is different
>> from the other. But... it's little things like the foldr' function NOT being
>> present in one library but present in the other, presumably a lazy
>> implementation doesn't need a strict function or something like that. Who
>> knows. I don't!
>>
>> I am sure to "seasoned" haskellers this is all elementary and I would love
>> to eventually become a seasoned developer of it too but at times like this I
>> want to scream in utter confusion as to how many different string types
>> there are and the sometimes almost unnotcable differences between them. And
>> trying to convert between them to actually get on and write useful working
>> code.
>>
>> When do I use strict? When do I use lazy? When do I use the Char8 variant?
>> And so the questions continue with barely any "beginner" level answers to be
>> found. I'd write them myself but I don't know the answers yet!
>>
>> Speaking as a non-academic, non-mathemetician, but as a developer with 25+
>> years of using lots of languages inclusing Erlang, LISP and Scala, sometimes
>> Haskell is very very hard to perservere with because everybody just seems to
>> love using words and phrases like "mono-morphism", "monadic transformers"
>> etc. just to show off how well they understand Haskell. That's fine for
>> those in the club but those on the outside looking in would also like to be
>> able to "get in" as well and be able to write serious looking blog posts
>> about how damned funky haskell is.
>>
>> And it is... but not if you can't understand it! is there some kind of Free
>> Masonry involved ;)
>>
>> Thanks again,
>>
>> Sean... now where's my RWH book again...
>>
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
------------------------------
Message: 4
Date: Fri, 9 Mar 2012 11:07:15 -0600
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] String type hello-o-matic...
To: Emacs The Viking <[email protected]>
Cc: [email protected]
Message-ID:
<cakjsnqezvxdl6sn9k8daxy4mdwp3y6uu1gnk6fbcmk6bbur...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On Fri, Mar 9, 2012 at 9:01 AM, Emacs The Viking <[email protected]> wrote:
>
> I am almost to the point of exasperation on trying to know when and why and
> how to convert between String, ByteString, ByteString.Laz, Char8 etc. For
> heavens sake how many bloody string types can you need? LOL
>
Here is a really important point I'd like to make:
The 'sha1' function operates on _binary_data_.
If you have a 'String' or a 'Text' value, you have to make a _choice_
how you wish to represent your textual data as binary data.
That's why their are multiple types - because different situations can
call for different choices.
The Data.ByteString.Char8 module makes one choice - it truncates all
Unicode code-points above 255 to 255.
In many circumstances, this is not the right choice. But it's not
always the wrong choice either.
A great choice is UTF-8 - available either in the module
Data.Text.Encoding (for 'Text' values) or in the utf8-string package
for String values (using the functions 'fromString' and 'toString').
Antoine
http://hackage.haskell.org/packages/archive/text/0.11.1.13/doc/html/Data-Text-Encoding.html
http://hackage.haskell.org/packages/archive/utf8-string/0.3.7/doc/html/Data-ByteString-UTF8.html
------------------------------
Message: 5
Date: Fri, 9 Mar 2012 21:07:24 +0200
From: Ovidiu Deac <[email protected]>
Subject: [Haskell-beginners] tuple update
To: beginners <[email protected]>
Message-ID:
<CAKVsE7uFw=kubzpnfrxnmsjiwe4dvrcwdj7cyh6ianavucz...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Does anybody know if there are any functions like these in the Haskell
libray?
updateSnd f (x,y) -> (x, f y)
updateFst f (x,y) -> (f x, y)
Thanks,
ovidiu
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120309/6a3011ff/attachment-0001.htm>
------------------------------
Message: 6
Date: Fri, 9 Mar 2012 14:09:53 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] tuple update
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Mar 09, 2012 at 09:07:24PM +0200, Ovidiu Deac wrote:
> Does anybody know if there are any functions like these in the Haskell
> libray?
>
> updateSnd f (x,y) -> (x, f y)
>
> updateFst f (x,y) -> (f x, y)
Yes: 'first' and 'second' from Control.Arrow.
-Brent
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 45, Issue 9
****************************************