Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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


Today's Topics:

   1. Re:  How to use Text.Printf w/ custom types (Baa)
   2. Re:  How to use Text.Printf w/ custom types (Norbert Melzer)
   3. Re:  How to use Text.Printf w/ custom types (Baa)
   4. Re:  Why do i need to specify the class of a here at all?
      (Quentin Liu)


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

Message: 1
Date: Fri, 24 Nov 2017 16:07:19 +0200
From: Baa <aqua...@gmail.com>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to use Text.Printf w/ custom
        types
Message-ID: <20171124160719.7292469f@Pavel>
Content-Type: text/plain; charset=US-ASCII

I talked about PrintfType and its method `hspr`.

With PrintfArgs the same problem:

  instance PrintfArg JobEvent where
    toUPrintf _ = UString "aaa"

      ^^^ toUPrintf is not visible ERROR here...

Header of this file looks like:

  module Text.Printf(
     printf, hPrintf,
     PrintfType, HPrintfType, PrintfArg, IsChar
  ) where

so methods are not exported? And I don't see any Internal subpackage...
OK, no problem, I switched already to very cool `formatting` library :)

Thanks a lot!


> It appears PrintfArg and its methods are fully exported.
> 
> On Fri, Nov 24, 2017 at 8:19 AM, Baa <aqua...@gmail.com> wrote:
> 
> > But how to do it if "methods" are not exporting?
> >  
> > > According to
> > > https://hackage.haskell.org/package/base-4.10.0.0/docs/  
> > Text-Printf.html#g:2,  
> > > you only need to implement `PrintfArg`. There is also an example
> > > for `()`.
> > >
> > > Baa <aqua...@gmail.com> schrieb am Fr., 24. Nov. 2017 um 13:33
> > > Uhr: 
> > > > Hello All!
> > > >
> > > > As I understand to use Text.Printf.printf with custom types or
> > > > to return result as Text instead of String I must implement some
> > > > class instances: PrintfType, PrintfArg. But how to do this if
> > > > they are exported from module as type-names only - without its
> > > > methods (i.e. not "Printf (..)", but "Printf") ?
> > > >
> > > > I tried to import Text.Printf.Internal but seems that no such
> > > > submodule...
> > > >
> > > > Any ideas?
> > > >
> > > > ===
> > > > Best regards, Paul
> > > > _______________________________________________
> > > > Beginners mailing list
> > > > Beginners@haskell.org
> > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > > >  
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners@haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >  



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

Message: 2
Date: Fri, 24 Nov 2017 15:36:25 +0000
From: Norbert Melzer <timmel...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] How to use Text.Printf w/ custom
        types
Message-ID:
        <ca+bcvsutkmspfr9uvqwjazsez4wuwen3bapb-2ddkdf2bz+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

PrintfArg does not have toUPrint. The functions in there are formatArg and
parseFormat.

PrintfType is according to its documentation, an interface that you shall
not implement yourself.

Baa <aqua...@gmail.com> schrieb am Fr., 24. Nov. 2017 um 15:08 Uhr:

> I talked about PrintfType and its method `hspr`.
>
> With PrintfArgs the same problem:
>
>   instance PrintfArg JobEvent where
>     toUPrintf _ = UString "aaa"
>
>       ^^^ toUPrintf is not visible ERROR here...
>
> Header of this file looks like:
>
>   module Text.Printf(
>      printf, hPrintf,
>      PrintfType, HPrintfType, PrintfArg, IsChar
>   ) where
>
> so methods are not exported? And I don't see any Internal subpackage...
> OK, no problem, I switched already to very cool `formatting` library :)
>
> Thanks a lot!
>
>
> > It appears PrintfArg and its methods are fully exported.
> >
> > On Fri, Nov 24, 2017 at 8:19 AM, Baa <aqua...@gmail.com> wrote:
> >
> > > But how to do it if "methods" are not exporting?
> > >
> > > > According to
> > > > https://hackage.haskell.org/package/base-4.10.0.0/docs/
> > > Text-Printf.html#g:2,
> > > > you only need to implement `PrintfArg`. There is also an example
> > > > for `()`.
> > > >
> > > > Baa <aqua...@gmail.com> schrieb am Fr., 24. Nov. 2017 um 13:33
> > > > Uhr:
> > > > > Hello All!
> > > > >
> > > > > As I understand to use Text.Printf.printf with custom types or
> > > > > to return result as Text instead of String I must implement some
> > > > > class instances: PrintfType, PrintfArg. But how to do this if
> > > > > they are exported from module as type-names only - without its
> > > > > methods (i.e. not "Printf (..)", but "Printf") ?
> > > > >
> > > > > I tried to import Text.Printf.Internal but seems that no such
> > > > > submodule...
> > > > >
> > > > > Any ideas?
> > > > >
> > > > > ===
> > > > > Best regards, Paul
> > > > > _______________________________________________
> > > > > Beginners mailing list
> > > > > Beginners@haskell.org
> > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > > > >
> > >
> > > _______________________________________________
> > > Beginners mailing list
> > > Beginners@haskell.org
> > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > >
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171124/ffd2991f/attachment-0001.html>

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

Message: 3
Date: Fri, 24 Nov 2017 18:23:55 +0200
From: Baa <aqua...@gmail.com>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to use Text.Printf w/ custom
        types
Message-ID: <20171124182355.7a8b0726@Pavel>
Content-Type: text/plain; charset=US-ASCII

Oh, seems that it's my error! You are right.

> PrintfArg does not have toUPrint. The functions in there are
> formatArg and parseFormat.
> 
> PrintfType is according to its documentation, an interface that you
> shall not implement yourself.
> 
> Baa <aqua...@gmail.com> schrieb am Fr., 24. Nov. 2017 um 15:08 Uhr:
> 
> > I talked about PrintfType and its method `hspr`.
> >
> > With PrintfArgs the same problem:
> >
> >   instance PrintfArg JobEvent where
> >     toUPrintf _ = UString "aaa"
> >
> >       ^^^ toUPrintf is not visible ERROR here...
> >
> > Header of this file looks like:
> >
> >   module Text.Printf(
> >      printf, hPrintf,
> >      PrintfType, HPrintfType, PrintfArg, IsChar
> >   ) where
> >
> > so methods are not exported? And I don't see any Internal
> > subpackage... OK, no problem, I switched already to very cool
> > `formatting` library :)
> >
> > Thanks a lot!
> >
> >  
> > > It appears PrintfArg and its methods are fully exported.
> > >
> > > On Fri, Nov 24, 2017 at 8:19 AM, Baa <aqua...@gmail.com> wrote:
> > >  
> > > > But how to do it if "methods" are not exporting?
> > > >  
> > > > > According to
> > > > > https://hackage.haskell.org/package/base-4.10.0.0/docs/  
> > > > Text-Printf.html#g:2,  
> > > > > you only need to implement `PrintfArg`. There is also an
> > > > > example for `()`.
> > > > >
> > > > > Baa <aqua...@gmail.com> schrieb am Fr., 24. Nov. 2017 um 13:33
> > > > > Uhr:  
> > > > > > Hello All!
> > > > > >
> > > > > > As I understand to use Text.Printf.printf with custom types
> > > > > > or to return result as Text instead of String I must
> > > > > > implement some class instances: PrintfType, PrintfArg. But
> > > > > > how to do this if they are exported from module as
> > > > > > type-names only - without its methods (i.e. not "Printf
> > > > > > (..)", but "Printf") ?
> > > > > >
> > > > > > I tried to import Text.Printf.Internal but seems that no
> > > > > > such submodule...
> > > > > >
> > > > > > Any ideas?
> > > > > >
> > > > > > ===
> > > > > > Best regards, Paul
> > > > > > _______________________________________________
> > > > > > Beginners mailing list
> > > > > > Beginners@haskell.org
> > > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > > > > >  
> > > >
> > > > _______________________________________________
> > > > Beginners mailing list
> > > > Beginners@haskell.org
> > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > > >  
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners@haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >  



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

Message: 4
Date: Fri, 24 Nov 2017 14:04:39 -0500
From: Quentin Liu <quentin.liu.0...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Why do i need to specify the class of
        a here at all?
Message-ID: <5fdec6dc-aeb8-4083-9782-114c0c1c8b6c@Spark>
Content-Type: text/plain; charset="utf-8"


> > > Yes, you could pass the function a list of strings as well. A string is 
> > > just a list of Chars. The type signature `a` does not restrict the range 
> > > of types you could pass to the function.
> >
> > That seem strange to me. Wouldn't that mean that i could write the 
> > declaration of myOrderFunc as `myOrderFunc :: a -> a -> Ordering` as well? 
> > GHCI give me an error on this though so obviously it's wrong. I just don't 
> > see why. Why cannot a represent [b]?

Could you copy and paste the error message here?

The type signature `a` means it could be anything, `String`, `[String]`, or any 
ADT you could come up with. So in a type signature if you write
  func :: a -> a -> a
     func a b = a
this funciton is telling ghc that I have a function that accepts two parameters 
that must be of the same type, whatever the type is. So `a` could be an ADT, a 
list, a list of lists, etc. But if you write
  func :: a -> [b] -> a
  func a bs = a
you are essentially saying this function would only take two parameters of two 
types (`a` and `b` could be of the same type) and the second parameter must be 
a list. This, however, does not suggest mean that `[b]` could not be 
`[[String]]`, for `[String]` could just be thought of as a `b`. The way I use 
to think about type signature is, when you trying to substitute type variables 
such as `a`, substitute it into a concrete type that you are working with.

Regards,
Qingbo Liu

On Nov 23, 2017, 03:19 -0500, mrx <patrik....@gmail.com>, wrote:
> > On Wed, Nov 22, 2017 at 10:40 PM, Quentin Liu <quentin.liu.0...@gmail.com> 
> > wrote:
> > > Hi Patrik,
> > >
> > > The reason for the requirement of “Eq a” in your `sortListOfLists` is 
> > > that you are calling myOrderFunc which carries the signature “Eq a”. If 
> > > you remove the `Eq` declaration in `myOrderFunc` the compiler then would 
> > > not complain about the absence of `Eq` in `sortListOfLists`. For a 
> > > detailed explanation you could reference chapter 6 of Real World Haskell.
> >
> > Thanks a lot for the reference. I'll make sure to read that chapter soon.
> >
> > >
> > > Yes, you could pass the function a list of strings as well. A string is 
> > > just a list of Chars. The type signature `a` does not restrict the range 
> > > of types you could pass to the function.
> >
> > That seem strange to me. Wouldn't that mean that i could write the 
> > declaration of myOrderFunc as `myOrderFunc :: a -> a -> Ordering` as well? 
> > GHCI give me an error on this though so obviously it's wrong. I just don't 
> > see why. Why cannot a represent [b]?
> >
> // Patrik
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171124/14b82385/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 113, Issue 23
******************************************

Reply via email to