How to use Text.Printf w/ custom types

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Baa
Reply | Threaded
Open this post in threaded view
|

How to use Text.Printf w/ custom types

Baa
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to use Text.Printf w/ custom types

Norbert Melzer
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 <[hidden email]> 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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Baa
Reply | Threaded
Open this post in threaded view
|

Re: How to use Text.Printf w/ custom types

Baa
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 <[hidden email]> 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
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >  

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to use Text.Printf w/ custom types

Norbert Melzer
Which methods?

Just doing this should be sufficient:

```
instance PrintfArg YourType where
  formatArg _ _ = Text.pack "It works (well, nearly)"
```

Baa <[hidden email]> schrieb am Fr., 24. Nov. 2017 um 14:20 Uhr:
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 <[hidden email]> 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
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to use Text.Printf w/ custom types

David McBride
In reply to this post by Baa
It appears PrintfArg and its methods are fully exported.

On Fri, Nov 24, 2017 at 8:19 AM, Baa <[hidden email]> 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 <[hidden email]> 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
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Baa
Reply | Threaded
Open this post in threaded view
|

Re: How to use Text.Printf w/ custom types

Baa
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 <[hidden email]> 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 <[hidden email]> 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
> > > > [hidden email]
> > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > > >  
> >
> > _______________________________________________
> > Beginners mailing list
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >  

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to use Text.Printf w/ custom types

Norbert Melzer
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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
> > > > [hidden email]
> > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > > >
> >
> > _______________________________________________
> > Beginners mailing list
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Baa
Reply | Threaded
Open this post in threaded view
|

Re: How to use Text.Printf w/ custom types

Baa
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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
> > > > > > [hidden email]
> > > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > > > > >  
> > > >
> > > > _______________________________________________
> > > > Beginners mailing list
> > > > [hidden email]
> > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > > >  
> >
> > _______________________________________________
> > Beginners mailing list
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >  

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners