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. Install on "foreign" server problem (Lawrence Bottorff)
2. Re: Simple UTF-8 output (Elvio Toccalino)
3. Re: Simple UTF-8 output (Christopher Howard)
4. Re: Simple UTF-8 output (Elvio Toccalino)
5. Data.Foldable/foldMap question (Patrick LeBoutillier)
6. Re: Data.Foldable/foldMap question (Daniel Fischer)
7. return IO () vs. () (Neil Jensen)
8. Re: return IO () vs. () (Alex Rozenshteyn)
----------------------------------------------------------------------
Message: 1
Date: Sat, 28 May 2011 10:42:07 -0500
From: Lawrence Bottorff <[email protected]>
Subject: [Haskell-beginners] Install on "foreign" server problem
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I'm trying to install the binary of 7.0.3 on a Bluehost.com server where I
have an account and ssh shell. I want to eventually run Yesod or happstack
or some other sort of haskell on web. I've talked with their tech support
and they're cool with it as long as it's in-place. Good. I try the
./configure and it errors saying things like:
checking for path to top of build tree...
utils/ghc-pwd/dist/build/tmp/ghc-pwd: /lib64/libc.so.6: version `GLIBC_2.9'
not found (required by utils/ghc-pwd/dist/build/tmp/ghc-pwd)
utils/ghc-pwd/dist/build/tmp/ghc-pwd: /lib64/libc.so.6: version `GLIBC_2.7'
not found (required by utils/ghc-pwd/dist/build/tmp/ghc-pwd)
configure: error: cannot determine current directory
I'm not (nor ever was) much of a sysadmin type. Any advice?
Actually, I'm just trying to do Web with Haskell on a server/cloud other
than my own home box. I have a Web client and I'd like to get us off PHP.
Any Haskell-friendly clouds/hosts to suggest?
Olwe
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110528/b097ce80/attachment-0001.htm>
------------------------------
Message: 2
Date: Sat, 28 May 2011 13:56:06 -0300
From: Elvio Toccalino <[email protected]>
Subject: Re: [Haskell-beginners] Simple UTF-8 output
To: Christopher Howard <[email protected]>
Cc: [email protected]
Message-ID: <1306601768.1616.4.camel@el-fierro>
Content-Type: text/plain; charset="UTF-8"
In case your ini file is not the problem, check the output of your
conversion piped (mentioned in the other mail: Data.Text.IO.putStrLn $
Data.Text.Encodings.decodeUtf8 $ bytestringResult) using decodeASCII,
just to see what comes out.
BTW, the \xe6 is the UTF8 code for the small letter AE, which I'm
guessing is not something you'd use in a query string :P
Unless you're storing some very cosmopolitan data in your database, I?d
say someone is messing your codes. So far, this hasn't happened to me
using the Haskell libraries recommended here.
On Fri, 2011-05-27 at 20:35 -0800, Christopher Howard wrote:
> On 05/27/2011 08:01 PM, Christopher Howard wrote:
> > On 05/26/2011 11:38 PM, Erik de Castro Lopo wrote:
> >> Elvio Toccalino wrote:
> >>
> >>> I usually pull such values as ByteStrings. The utf8-strings package
> >>> provides printing functions for such data.
> >>> Also, if you'd like to work on it as Text, there's the
> >>> Data.Text.Encodings module, to decodeUTF8 or decodeASCII ByteString's
> >>> into Text.
> >>
> >> I would recommend Data.Text because that is designed for Text
> >> encodings while ByteString is designed for handling arrays
> >> of bytes (eg things like data read from an network socket).
> >>
> >> Cheers,
> >> Erik
> >
> > Thank you everyone for your responses, but I'm still having trouble with
> > this issue. This is what I've learned so far:
> >
> > - The problem is not my terminal: commands like putStrLn "\228" produce
> > the correct character.
> > - The problem doesn't seem to be my MySQL database. The character
> > encoding on the database and on the table are set to UTF-8. I can view
> > the characters just fine when in the MySQL client.
> > - I looked again at the character numbers on the special characters
> > being outputted by my program: They are not the correct Unicode numbers.
> > Apparently the special characters are somehow getting mangled when I
> > pull them from the database.
> > - The choice to put the query results into ByteStrings was not mine,
> > that is just what is in the results list that quickQuery gives me. I
> > tried converting to Text and then to String by using "unpack (decodeUtf8
> > byte_str)"; however, when the program goes to print its first line with
> > an extended character, it just throws the exception: "*** Exception:
> > Cannot decode byte '\xe6': Data.Text.Encoding.decodeUtf8: Invalid UTF-8
> > stream".
> >
>
> Update: I think this may be a problem with the myodbc5 driver. If I
> connect with isql and then select the data, the results with extended
> characters have the text either mangled or replaced with "***ERROR***".
> So I am thinking either this MySQL driver for unixODBC either is not
> able to handle the UTF-8, or (more likely) I don't have the correct
> options in my .odbc.ini config file.
>
------------------------------
Message: 3
Date: Sat, 28 May 2011 09:58:07 -0800
From: Christopher Howard <[email protected]>
Subject: Re: [Haskell-beginners] Simple UTF-8 output
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
On 05/28/2011 08:56 AM, Elvio Toccalino wrote:
> In case your ini file is not the problem, check the output of your
> conversion piped (mentioned in the other mail: Data.Text.IO.putStrLn $
> Data.Text.Encodings.decodeUtf8 $ bytestringResult) using decodeASCII,
> just to see what comes out.
>
> BTW, the \xe6 is the UTF8 code for the small letter AE, which I'm
> guessing is not something you'd use in a query string :P
> Unless you're storing some very cosmopolitan data in your database, I?d
> say someone is messing your codes. So far, this hasn't happened to me
> using the Haskell libraries recommended here.
>
Actually, e6 was the correct UTF-8 hex value (ligature ?). Used as part
of a book title.
To be honest, I finally gave up on Database.HDBC.ODBC and tried the
experimental Database.HDBC.MySQL. So far it appears to be getting the
Unicode right.
--
frigidcode.com
theologia.indicium.us
------------------------------
Message: 4
Date: Sat, 28 May 2011 15:39:43 -0300
From: Elvio Toccalino <[email protected]>
Subject: Re: [Haskell-beginners] Simple UTF-8 output
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <1306607986.1616.9.camel@el-fierro>
Content-Type: text/plain; charset="UTF-8"
> On 05/28/2011 08:56 AM, Elvio Toccalino wrote:
> > BTW, the \xe6 is the UTF8 code for the small letter AE, which I'm
> > guessing is not something you'd use in a query string :P
On Sat, 2011-05-28 at 09:58 -0800, Christopher Howard wrote:
> Actually, e6 was the correct UTF-8 hex value (ligature ?). Used as part
> of a book title.
Aggressive inference can be a bitch sometimes.
Keep reporting on you're adventures, Chris. And if you keep having
problems with a library, suspecting it's a bug, please let the right
people know about it.
------------------------------
Message: 5
Date: Sat, 28 May 2011 16:37:45 -0400
From: Patrick LeBoutillier <[email protected]>
Subject: [Haskell-beginners] Data.Foldable/foldMap question
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I'm reading the LYAH book and on page 263 it says that if you define
Data.Foldable.foldMap you get Data.Foldable.foldl and
Data.Foldable.foldl for "free". The default implementation code of
Data.Foldable.foldr is:
foldr :: (a -> b -> b) -> b -> t a -> b
foldr f z t = appEndo (foldMap (Endo . f) t) z
I don't understand this code, but more specifically I don't get how
there can a Monoid constraint on foldMap's return type and not on
foldr/foldl.
Can any one explain what Endo is and how it works?
Thanks a lot,
Patrick
--
=====================
Patrick LeBoutillier
Rosem?re, Qu?bec, Canada
------------------------------
Message: 6
Date: Sat, 28 May 2011 23:10:17 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Data.Foldable/foldMap question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Saturday 28 May 2011 22:37:45, Patrick LeBoutillier wrote:
> Hi,
>
> I'm reading the LYAH book and on page 263 it says that if you define
> Data.Foldable.foldMap you get Data.Foldable.foldl and
> Data.Foldable.foldl for "free". The default implementation code of
> Data.Foldable.foldr is:
>
> foldr :: (a -> b -> b) -> b -> t a -> b
> foldr f z t = appEndo (foldMap (Endo . f) t) z
>
> I don't understand this code, but more specifically I don't get how
> there can a Monoid constraint on foldMap's return type and not on
> foldr/foldl.
>
> Can any one explain what Endo is and how it works?
newtype Endo a = Endo { appEndo :: a -> a }
So an (Endo a) is a wrapped function (a -> a), an endomorphism of a (in the
category Hask; ignore this if you don't know what that means).
The type of f in foldr is
f :: a -> b -> b = a -> (b -> b),
hence (f x) :: (b -> b) and
Endo . f :: a -> Endo b
and there is a Monoid instance for (Endo b)
(mempty is (Endo id), (Endo g) `mappend` (Endo h) = Endo (g . h)), so
(Endo . f) is a suitable argument for foldMap.
foldMap (Endo . f) t builds an endomorphism of b [wrapped in the newtype],
which is then unwrapped by appEndo to yield a function (b -> b) which
finally is applied to the supplied element z of b.
Without the wrapper and for lists:
foldr f z [1,2,3]
~> f 1 (foldr f z [2,3]) === (f 1) (foldr f z [2,3])
~> (f 1) ((f 2) (foldr f z [3]))
= ((f 1) . (f 2)) (foldr f z [3])
~> ((f 1) . (f 2)) ((f 3) (foldr f z []))
~> ((f 1) . (f 2) . (f 3)) (foldr f z [])
~> ((f 1) . (f 2) . (f 3)) z
The composition (f 1) . (f 2) . (f 3) is what foldMap builds [modulo the
wrapper Endo, with the wrapper it is
Endo (f 1) `mappend` Endo (f 2) `mappend` Endo (f 3)
= Endo ((f 1) . (f 2) . (f 3))
which is then unwrapped by appEndo].
>
>
> Thanks a lot,
>
> Patrick
------------------------------
Message: 7
Date: Sat, 28 May 2011 14:35:11 -0700
From: Neil Jensen <[email protected]>
Subject: [Haskell-beginners] return IO () vs. ()
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I've been attempting to refactor some working code and running into
confusion about returning IO values.
The basic sequence is to query a database, calculate some values, and then
store the results back in the database.
The function which does the querying of the db and calculating results has
the following type signature:
calcCUVs :: AccountId -> IO [((ISODateInt, ISODateInt), CUV)]
This function stores the results back into the database
saveCUVs :: AccountId -> [((ISODateInt, ISODateInt), CUV)] -> IO ()
saveCUVs account cuvs = do
r' <- mapM (\x -> storeCUV (snd $ fst x) account (snd x)) cuvs
return ()
I had a working variation of the below using 'do' notation, but for some
reason when I moved to using bind, I'm getting messed up with return values.
processAccountCUVs :: AccountId -> ISODateInt -> ISODateInt -> IO ()
processAccountCUVs account prevMonthEnd monthEnd = -- do
if (prevMonthEnd == 0 && monthEnd == 0)
then calcCUVs account >>= (\cuvs -> saveCUVs account
cuvs) >>= return ()
else calcCUVs account prevMonthEnd monthEnd >>=
(\cuvs -> saveCUVs account cuvs) >>= return ()
The compiler gives the following error message:
Couldn't match expected type `IO ()' against inferred type `()'
In the first argument of `return', namely `()'
In the second argument of `(>>=)', namely `return ()'
In the expression:
calcCUVs account >>= (\ cuvs -> saveCUVs account cuvs) >>=
return ()
I thought the last return () would correctly return us IO () as we are in
the IO monad... what am I missing?
Thanks for any input you can provide.
Neil
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110528/7691c607/attachment-0001.htm>
------------------------------
Message: 8
Date: Sat, 28 May 2011 17:50:25 -0400
From: Alex Rozenshteyn <[email protected]>
Subject: Re: [Haskell-beginners] return IO () vs. ()
To: Neil Jensen <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
The thing that I see as weird is (>>= return ()), since the right argument
to (>>=) is supposed to be a function.
Maybe you want (>>)
On Sat, May 28, 2011 at 5:35 PM, Neil Jensen <[email protected]> wrote:
> I've been attempting to refactor some working code and running into
> confusion about returning IO values.
>
> The basic sequence is to query a database, calculate some values, and then
> store the results back in the database.
>
> The function which does the querying of the db and calculating results has
> the following type signature:
> calcCUVs :: AccountId -> IO [((ISODateInt, ISODateInt), CUV)]
>
> This function stores the results back into the database
> saveCUVs :: AccountId -> [((ISODateInt, ISODateInt), CUV)] -> IO ()
> saveCUVs account cuvs = do
> r' <- mapM (\x -> storeCUV (snd $ fst x) account (snd x)) cuvs
> return ()
>
>
> I had a working variation of the below using 'do' notation, but for some
> reason when I moved to using bind, I'm getting messed up with return values.
>
> processAccountCUVs :: AccountId -> ISODateInt -> ISODateInt -> IO ()
> processAccountCUVs account prevMonthEnd monthEnd = -- do
> if (prevMonthEnd == 0 && monthEnd == 0)
> then calcCUVs account >>= (\cuvs -> saveCUVs
> account cuvs) >>= return ()
> else calcCUVs account prevMonthEnd monthEnd >>=
> (\cuvs -> saveCUVs account cuvs) >>= return ()
>
>
> The compiler gives the following error message:
>
> Couldn't match expected type `IO ()' against inferred type `()'
> In the first argument of `return', namely `()'
> In the second argument of `(>>=)', namely `return ()'
> In the expression:
> calcCUVs account >>= (\ cuvs -> saveCUVs account cuvs) >>=
> return ()
>
>
> I thought the last return () would correctly return us IO () as we are in
> the IO monad... what am I missing?
>
> Thanks for any input you can provide.
> Neil
>
>
>
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
--
Alex R
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110528/07f80f93/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 35, Issue 56
*****************************************