Re: [Haskell-cafe] different behaviours with or without putStrLn
One question: Since it works with putStrLn, can I simulate the behaviour of putStrLn without actually... printing anything? As a workaround... On Mon, Jan 13, 2014 at 12:40 AM, Corentin Dupont <corentin.dupont@gmail.com
wrote:
I doesn't seems to be easy, either with deepseq-th or deepseq-generic... With deepseq-generic, the derivation of Generic doesn't work because I'm using a GATD. It says *"NewVar must be a vanilla data constructor"*.
For deepseq-th, I have this error:
*deriveNFData: 'forall' not supported in constructor declaration* I have some complex data constructor...
So it looks like both deepseq-th and deepseq-generic are out of the game :((
On Mon, Jan 13, 2014 at 12:08 AM, Erik de Castro Lopo < mle+hs@mega-nerd.com> wrote:
James ‘Twey’ Kay wrote:
You can (probably) automatically derive it via Template Haskell using the deepseq-th package:
{-# LANGUAGE TemplateHaskell #-} import Control.DeepSeq.TH
data MyState = ...
$(deriveNFData ''MyState)
In most cases where you think
You should probably try the deepseq-generics package before you try deepseq-th.
The generics version was suggested to me by the author of the TH version, Herbert Valerio Riedel. It seems to be just as fast as the TH version and doesn't require TH.
Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/ _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Sure, something along the lines of deepseq . show will probably have the same effect. On Sunday, January 12, 2014, Corentin Dupont wrote:
One question: Since it works with putStrLn, can I simulate the behaviour of putStrLn without actually... printing anything? As a workaround...
On Mon, Jan 13, 2014 at 12:40 AM, Corentin Dupont < corentin.dupont@gmail.com <javascript:_e({}, 'cvml', 'corentin.dupont@gmail.com');>> wrote:
I doesn't seems to be easy, either with deepseq-th or deepseq-generic... With deepseq-generic, the derivation of Generic doesn't work because I'm using a GATD. It says *"NewVar must be a vanilla data constructor"*.
For deepseq-th, I have this error:
*deriveNFData: 'forall' not supported in constructor declaration* I have some complex data constructor...
So it looks like both deepseq-th and deepseq-generic are out of the game :((
On Mon, Jan 13, 2014 at 12:08 AM, Erik de Castro Lopo < mle+hs@mega-nerd.com <javascript:_e({}, 'cvml', 'mle+hs@mega-nerd.com');>
wrote:
James ‘Twey’ Kay wrote:
You can (probably) automatically derive it via Template Haskell using the deepseq-th package:
{-# LANGUAGE TemplateHaskell #-} import Control.DeepSeq.TH
data MyState = ...
$(deriveNFData ''MyState)
In most cases where you think
You should probably try the deepseq-generics package before you try deepseq-th.
The generics version was suggested to me by the author of the TH version, Herbert Valerio Riedel. It seems to be just as fast as the TH version and doesn't require TH.
Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/ _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org <javascript:_e({}, 'cvml', 'Haskell-Cafe@haskell.org');> http://www.haskell.org/mailman/listinfo/haskell-cafe
On Sun, Jan 12, 2014 at 6:44 PM, Corentin Dupont <corentin.dupont@gmail.com>wrote:
One question: Since it works with putStrLn, can I simulate the behaviour of putStrLn without actually... printing anything? As a workaround...
Worst case, open a handle on /dev/null and hPutStr to it. I'd probably try to figure out how to write appropriate NFData instances, though. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Hi, I've tried the make an instance of NFData for all types, although I have a problem with the GATD: *data MyGADT a where MyField :: b -> MyGADT (Maybe b)instance NFData a => NFData (MyGADT a) where rnf (MyField b) = (rnf b)* Gives me : Could not deduce (NFData b) arising from a use of `rnf' from the context (NFData a) Which I understand (that's because a ~ *Maybe b *and not* a ~ b *due to the declaration of *MyField b *being of type *MyGADT (Maybe b)*) *But I have no idea how to solve that??* *Thanks...* *Corentin* On Mon, Jan 13, 2014 at 1:10 AM, Brandon Allbery <allbery.b@gmail.com>wrote:
On Sun, Jan 12, 2014 at 6:44 PM, Corentin Dupont < corentin.dupont@gmail.com> wrote:
One question: Since it works with putStrLn, can I simulate the behaviour of putStrLn without actually... printing anything? As a workaround...
Worst case, open a handle on /dev/null and hPutStr to it.
I'd probably try to figure out how to write appropriate NFData instances, though.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Try *instance NFData a => NFData (MyGADT (Maybe a) )* On Sunday, January 19, 2014, Corentin Dupont <corentin.dupont@gmail.com> wrote:
Hi, I've tried the make an instance of NFData for all types, although I have a problem with the GATD:
*data MyGADT a where MyField :: b -> MyGADT (Maybe b) instance NFData a => NFData (MyGADT a) where rnf (MyField b) = (rnf b)* Gives me : Could not deduce (NFData b) arising from a use of `rnf' from the context (NFData a)
Which I understand (that's because a ~ *Maybe b *and not* a ~ b *due to the declaration of *MyField b *being of type *MyGADT (Maybe b)*)
*But I have no idea how to solve that?? *
*Thanks...*
*Corentin*
On Mon, Jan 13, 2014 at 1:10 AM, Brandon Allbery <allbery.b@gmail.com<javascript:_e({}, 'cvml', 'allbery.b@gmail.com');>
wrote:
On Sun, Jan 12, 2014 at 6:44 PM, Corentin Dupont < corentin.dupont@gmail.com <javascript:_e({}, 'cvml', 'corentin.dupont@gmail.com');>> wrote:
One question: Since it works with putStrLn, can I simulate the behaviour of putStrLn without actually... printing anything? As a workaround...
Worst case, open a handle on /dev/null and hPutStr to it.
I'd probably try to figure out how to write appropriate NFData instances, though.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com <javascript:_e({}, 'cvml', 'allbery.b@gmail.com');> ballbery@sinenomine.net <javascript:_e({}, 'cvml', 'ballbery@sinenomine.net');> unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
For that to work, I believe you must enable FlexibleInstances and possibly also OverlappingInstances (depending on what the rest of the GADT looks like). On Sun, Jan 19, 2014 at 3:00 PM, Carter Schonwald < carter.schonwald@gmail.com> wrote:
Try
*instance NFData a => NFData (MyGADT (Maybe a) )*
On Sunday, January 19, 2014, Corentin Dupont <corentin.dupont@gmail.com> wrote:
Hi, I've tried the make an instance of NFData for all types, although I have a problem with the GATD:
*data MyGADT a where MyField :: b -> MyGADT (Maybe b) instance NFData a => NFData (MyGADT a) where rnf (MyField b) = (rnf b)* Gives me : Could not deduce (NFData b) arising from a use of `rnf' from the context (NFData a)
Which I understand (that's because a ~ *Maybe b *and not* a ~ b *due to the declaration of *MyField b *being of type *MyGADT (Maybe b)*)
*But I have no idea how to solve that?? *
*Thanks...*
*Corentin*
On Mon, Jan 13, 2014 at 1:10 AM, Brandon Allbery <allbery.b@gmail.com>wrote:
On Sun, Jan 12, 2014 at 6:44 PM, Corentin Dupont < corentin.dupont@gmail.com> wrote:
One question: Since it works with putStrLn, can I simulate the behaviour of putStrLn without actually... printing anything? As a workaround...
Worst case, open a handle on /dev/null and hPutStr to it.
I'd probably try to figure out how to write appropriate NFData instances, though.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Off the top of my head i can think of two non-overlapping solution, both are ugly but maybe someone has an idea to make one nice: The first is to bake the constraint into the GADT: data MyGADT a where MyField :: NFData b => b -> MyGADT (Maybe b) instance NFData (MyGADT a) where rnf (MyField b) = rnf b This is bad because NFData should have nothing to do with the definition of the datastructure The second is to use implication constraints: import Data.Constraint data MyGADT a where MyField :: b -> MyGADT (Maybe b) newtype Constr a = Constr (forall b. (a ~ Maybe b) :- NFData b) class DConstr a where constr :: Constr a instance (NFData a) => DConstr (Maybe a) where constr = Constr (Sub Dict) instance (DConstr a) => NFData (MyGADT a) where rnf (MyField b) = case constr :: Constr a of Constr (Sub Dict) -> rnf b this is ugly because for every non-Maybe index you need to define an "absurd" instance of DConstr. e.g. for Int: instance DConstr Int where constr = Constr undefined -- should be (Constr (Sub !absurd!)) but there is no way to denote absurdity in Haskell On 19 January 2014 23:16, Bob Ippolito <bob@redivi.com> wrote:
For that to work, I believe you must enable FlexibleInstances and possibly also OverlappingInstances (depending on what the rest of the GADT looks like).
On Sun, Jan 19, 2014 at 3:00 PM, Carter Schonwald < carter.schonwald@gmail.com> wrote:
Try
*instance NFData a => NFData (MyGADT (Maybe a) )*
On Sunday, January 19, 2014, Corentin Dupont <corentin.dupont@gmail.com> wrote:
Hi, I've tried the make an instance of NFData for all types, although I have a problem with the GATD:
*data MyGADT a where MyField :: b -> MyGADT (Maybe b) instance NFData a => NFData (MyGADT a) where rnf (MyField b) = (rnf b)* Gives me : Could not deduce (NFData b) arising from a use of `rnf' from the context (NFData a)
Which I understand (that's because a ~ *Maybe b *and not* a ~ b *due to the declaration of *MyField b *being of type *MyGADT (Maybe b)*)
*But I have no idea how to solve that?? *
*Thanks...*
*Corentin*
On Mon, Jan 13, 2014 at 1:10 AM, Brandon Allbery <allbery.b@gmail.com>wrote:
On Sun, Jan 12, 2014 at 6:44 PM, Corentin Dupont < corentin.dupont@gmail.com> wrote:
One question: Since it works with putStrLn, can I simulate the behaviour of putStrLn without actually... printing anything? As a workaround...
Worst case, open a handle on /dev/null and hPutStr to it.
I'd probably try to figure out how to write appropriate NFData instances, though.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Andras Slemmer -
Bob Ippolito -
Brandon Allbery -
Carter Schonwald -
Corentin Dupont