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: no instance for monad (Emmanuel Touzery)
2. Re: no instance for monad (Daniel Trstenjak)
3. Re: no instance for monad (Emmanuel Touzery)
4. Re: no instance for monad (Daniel Trstenjak)
5. Re: no instance for monad (Daniel Trstenjak)
6. Re: no instance for monad (Emmanuel Touzery)
----------------------------------------------------------------------
Message: 1
Date: Sat, 20 Oct 2012 21:53:09 +0200
From: Emmanuel Touzery <[email protected]>
Subject: Re: [Haskell-beginners] no instance for monad
To: [email protected]
Message-ID:
<CAC42Ren1vKni39=QQ5c4DJ7X04aPPO_7=K87U4=agwn+7eb...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Thank you! And yes that works...
But what if i do want to give several parameters to hprint? In my second
email i noted i get a different error message in that case?
so for instance:
TF.hprint handle " {} {}" "a" "b"
In that case I get that "no instance for.." error message.
No instance for (MonadIO ((->) t0))
arising from a use of `TF.hprint'
Possible fix: add an instance declaration for (MonadIO ((->) t0))
In the expression: TF.hprint handle " {} {}" "a" "b"
In the expression: do { TF.hprint handle " {} {}" "a" "b" }
In an equation for `writeProgramInfo':
writeProgramInfo handle program
= do { TF.hprint handle " {} {}" "a" "b" }
On 20 Oct 2012 21:48, "Daniel Trstenjak" <[email protected]> wrote:
>
> Hi Emmanuel,
>
> > writeProgramInfo :: Handle -> ProgramInfo -> IO ()
> > writeProgramInfo handle program = do
> > TF.hprint handle "hello"
> >
> > I get this error message at build time:
> >
> > Couldn't match expected type `IO ()'
> > with actual type `ps0 -> m0 ()'
> > In the return type of a call of `TF.hprint'
> > In the expression: TF.hprint handle "hello"
> > In the expression: do { TF.hprint handle "hello" }
>
> GHC expects an expression of 'IO ()' - the return type of writeProgramInfo
> -
> but the expression 'TF.hprint handle "hello"' has the type 'ps0 -> m0 ()'
>
> Look at the type of 'hprint':
> hprint :: (MonadIO m, Params ps) => Handle -> Format -> ps -> m ()
>
> Your call of 'hprint' is missing the last argument, the 'ps'. So
> instead of 'm ()' you're returing the function 'ps -> m()', that's
> what GHC tries to tell you.
>
>
> You might be confused, because 'hprintf' uses some magic to allow
> multiple parameters and can even be called without any parameter.
>
> 'hprint' uses are more explict - and imho a nicer and simpler approach -
> for the parameters, but the parameter can't be completly omitted,
> it has to be at least '()'.
>
> So in your case: TF.hprint handle "hello" ()
>
>
> Greetings,
> Daniel
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121020/203f19bc/attachment-0001.htm>
------------------------------
Message: 2
Date: Sat, 20 Oct 2012 22:02:53 +0200
From: Daniel Trstenjak <[email protected]>
Subject: Re: [Haskell-beginners] no instance for monad
To: [email protected]
Message-ID: <20121020200253.GB22084@machine>
Content-Type: text/plain; charset=us-ascii
On Sat, Oct 20, 2012 at 09:53:09PM +0200, Emmanuel Touzery wrote:
> Thank you! And yes that works...
>
> But what if i do want to give several parameters to hprint? In my second
> email i noted i get a different error message in that case?
> so for instance:
> TF.hprint handle " {} {}" "a" "b"
Look at the instances of the type class Params:
http://hackage.haskell.org/packages/archive/text-format/0.3.0.8/doc/html/Data-Text-Format-Params.html#t:Params
It tells us, that for multiple parameters you can use a list '["a", "b"]' or a
tuple
with up to ten elements '("a", "b")'.
Greetings,
Daniel
------------------------------
Message: 3
Date: Sat, 20 Oct 2012 22:12:39 +0200
From: Emmanuel Touzery <[email protected]>
Subject: Re: [Haskell-beginners] no instance for monad
To: [email protected]
Message-ID:
<cac42remcsqnp9wkwu7w3ulv6n2e_pkvjo6xg9bdm6-oxeha...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Thank you, you're right again. I had actually tried that but it failed and
I didn't look at the compilation error hard enough.
It said:
Ambiguous type variable `t0' in the constraints:
(Data.Text.Buildable.Buildable
t0) arising from a use of `TF.hprint' at JsonWriter.hs:94:17-25
(Data.String.IsString t0) arising from the literal `"b"'
at JsonWriter.hs:94:49-51
And now that thanks to your email I knew this was the right direction, I
read properly the error message and got to that working solution:
TF.hprint handle " {} {}" ["a" :: T.Text, "b" :: T.Text]
Unfortunately it's not very compact. I guess the problem is that this
Buildable data can take either a String or a Text and because I build with
OverloadedStrings the compiler doesn't know which one to prioritize?
If that's the case I wish Buildable would only accept Text and if you
really want to give a String you could always pack it. But maybe I'm
missing something. Is there no way to get a more compact line in this case?
Although most of the time it's true that the parameters for the print will
in fact be other values which were assigned and which type was determined
previously in the program.
Anyway thank you a lot, you unblocked me!
Emmanuel
On Sat, Oct 20, 2012 at 10:02 PM, Daniel Trstenjak <
[email protected]> wrote:
>
> On Sat, Oct 20, 2012 at 09:53:09PM +0200, Emmanuel Touzery wrote:
> > Thank you! And yes that works...
> >
> > But what if i do want to give several parameters to hprint? In my second
> > email i noted i get a different error message in that case?
> > so for instance:
> > TF.hprint handle " {} {}" "a" "b"
>
> Look at the instances of the type class Params:
>
> http://hackage.haskell.org/packages/archive/text-format/0.3.0.8/doc/html/Data-Text-Format-Params.html#t:Params
>
> It tells us, that for multiple parameters you can use a list '["a", "b"]'
> or a tuple
> with up to ten elements '("a", "b")'.
>
>
> Greetings,
> Daniel
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121020/87e2f86d/attachment-0001.htm>
------------------------------
Message: 4
Date: Sat, 20 Oct 2012 22:34:27 +0200
From: Daniel Trstenjak <[email protected]>
Subject: Re: [Haskell-beginners] no instance for monad
To: [email protected]
Message-ID: <20121020203426.GC22084@machine>
Content-Type: text/plain; charset=us-ascii
On Sat, Oct 20, 2012 at 10:12:39PM +0200, Emmanuel Touzery wrote:
> Thank you, you're right again. I had actually tried that but it failed and
> I didn't look at the compilation error hard enough.
>
> It said:
> Ambiguous type variable `t0' in the constraints:
> (Data.Text.Buildable.Buildable
> t0) arising from a use of `TF.hprint' at JsonWriter.hs:94:17-25
> (Data.String.IsString t0) arising from the literal `"b"'
> at JsonWriter.hs:94:49-51
>
> And now that thanks to your email I knew this was the right direction, I
> read properly the error message and got to that working solution:
>
> TF.hprint handle " {} {}" ["a" :: T.Text, "b" :: T.Text]
>
> Unfortunately it's not very compact. I guess the problem is that this
> Buildable data can take either a String or a Text and because I build with
> OverloadedStrings the compiler doesn't know which one to prioritize?
The issue arises, because Text and a type of the Json library you're
using, both have an instance for the type class IsString, which is
the base for the OverloadedStrings extension.
I don't now if there's a "nicer" way to tell GHC which one it should use.
Instead of giving each element a type you could give the whole list a type:
["a", "b"] :: [T.Text]
Greetings,
Daniel
------------------------------
Message: 5
Date: Sun, 21 Oct 2012 10:24:34 +0200
From: Daniel Trstenjak <[email protected]>
Subject: Re: [Haskell-beginners] no instance for monad
To: [email protected]
Message-ID: <20121021082434.GA6778@fly>
Content-Type: text/plain; charset=us-ascii
On Sat, Oct 20, 2012 at 10:34:27PM +0200, Daniel Trstenjak wrote:
> The issue arises, because Text and a type of the Json library you're
> using, both have an instance for the type class IsString, which is
> the base for the OverloadedStrings extension.
Well, now I didn't read the error message properly. You have been
absolutely right with your analysis.
> Instead of giving each element a type you could give the whole list a type:
> ["a", "b"] :: [T.Text]
Or you could add a helper function:
hprintT :: (MonadIO m) => Handle -> TF.Format -> [T.Text] -> m ()
hprintT = TF.hprint
Greetings,
Daniel
------------------------------
Message: 6
Date: Sun, 21 Oct 2012 11:42:30 +0200
From: Emmanuel Touzery <[email protected]>
Subject: Re: [Haskell-beginners] no instance for monad
To: [email protected]
Message-ID:
<cac42remc3pzey+dhsm61q-vedhut8desqmjptn7sykt25zy...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Thank you for the further tips.
The root of my problem, the reason I decided to use that text-format
library though, is because I thought Text.Printf is mangling unicode
characters because it's working on String and not on Data.Text.
However I realized now that even using text-format the unicode characters
were still not written correctly in the file (well there was an error
saving the file, invalid character, same as with Text.Printf). And I found
the correct fix: I must add:
hSetEncoding fileH utf8
After opening the file and before writing it in. If I do that, the unicode
characters are written OK, and even if I use the usual Text.Printf (and
even on windows - on linux where the locale is anyway utf8 it was working
from the start). So now I'm wondering should I even use text-format since
after all Text.Printf does the job? The author of text-format claims it's
written more efficiently but then again I don't believe there is any kind
of bottleneck there.
Emmanuel
On Sun, Oct 21, 2012 at 10:24 AM, Daniel Trstenjak <
[email protected]> wrote:
>
> On Sat, Oct 20, 2012 at 10:34:27PM +0200, Daniel Trstenjak wrote:
> > The issue arises, because Text and a type of the Json library you're
> > using, both have an instance for the type class IsString, which is
> > the base for the OverloadedStrings extension.
>
> Well, now I didn't read the error message properly. You have been
> absolutely right with your analysis.
>
> > Instead of giving each element a type you could give the whole list a
> type:
> > ["a", "b"] :: [T.Text]
>
> Or you could add a helper function:
>
> hprintT :: (MonadIO m) => Handle -> TF.Format -> [T.Text] -> m ()
> hprintT = TF.hprint
>
>
>
> Greetings,
> Daniel
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121021/567cb4a1/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 52, Issue 26
*****************************************