Search Haskell Channel Logs

Saturday, February 25, 2017

#haskell channel featuring centril, Welkin, cocreature, lpaste_, Tuplanolla, lambdabot, and 5 others.

Welkin 2017-02-25 04:50:54
not sure when or why you would use this
ph88^ 2017-02-25 04:52:16
i guess like unsafeCoerce but then safe :P
ph88^ 2017-02-25 04:54:15
why does the test work here https://bpaste.net/show/218564bb5c7c even though i have not put deriving (Typeable) on Foo ?
Tuplanolla 2017-02-25 04:54:29
That's `coerce`, ph88.
bollu 2017-02-25 04:54:49
Aku is not around I guess?
bollu 2017-02-25 04:54:53
did he come back?
ph88^ 2017-02-25 04:56:27
i don't understand this, the function requires that there is a typeclass on the type .. the class is not derived but it works anyway ?!
Tuplanolla 2017-02-25 04:57:38
GHC derives it implicitly, ph88.
ph88^ 2017-02-25 04:58:18
that's cheating :P
Tuplanolla 2017-02-25 04:58:27
The alternative was worse.
bollu 2017-02-25 04:58:35
Tuplanolla: which typeckass?
Tuplanolla 2017-02-25 04:58:48
`Typeable`, bollu.
bollu 2017-02-25 04:58:58
oh, OK
lyxia 2017-02-25 05:05:52
ph88^: coerce converts between types with a compile-time proof that they have the same runtime representation, cast checks at compile time whether two types are equal.
lyxia 2017-02-25 05:05:59
ph88^: uh, cast checks at runtime
ph88^ 2017-02-25 05:07:40
wouldn't i be better off using coerce then ?
lyxia 2017-02-25 05:09:27
I don't remember what you were trying to do. Both have their uses.
Welkin 2017-02-25 05:10:36
how can it check at runtime?
Welkin 2017-02-25 05:15:44
there is no type information at runtime
ph88^ 2017-02-25 05:15:44
lyxia, in a structure like Foo (Wrap T) (Bar (Wrap T)) (Wrap (Qux T)) i want to find the last T and modify it, i got a library for generics (generics-eot) but i needed a mechanism to check if a value is of a given type
lyxia 2017-02-25 05:15:44
Typeable implies a runtime representation of the type.
ph88^ 2017-02-25 05:15:44
yes that's what i expected too
lyxia 2017-02-25 05:16:07
you don't need to write anything
ph88^ 2017-02-25 05:16:49
lyxia, ya i've heard that ghc derives this automatically to do it's job. But afterwards the type information is removed at runtime unless you put deriving (Typeable) isn't that right ?
lyxia 2017-02-25 05:17:26
no...
Welkin 2017-02-25 05:18:07
there is no type information at runtime
ph88^ 2017-02-25 05:18:18
ok let's step back then .. why do you want/need to put deriving (Typeable) on a type when GHC already derives this for all types ?
Welkin 2017-02-25 05:18:21
typeable uses data to represent type information, if I understand
lyxia 2017-02-25 05:18:32
It inserts the type representative when you call a function with a Typeable constraint
lyxia 2017-02-25 05:18:37
ph88^: you don't
ph88^ 2017-02-25 05:18:52
oh lol
lyxia 2017-02-25 05:19:00
ph88^: there are bits of code on the web that do because they are old.
ph88^ 2017-02-25 05:19:07
ooh right ok
ph88^ 2017-02-25 05:20:00
lyxia, what extra parameter was it you were talking about a few lines back ?
ph88^ 2017-02-25 05:21:40
i guess a pointer to a thunk with type information ?
lyxia 2017-02-25 05:21:43
ph88^: Typeclasses are desugared into dictionaries.
lyxia 2017-02-25 05:22:11
ph88^: The Typeable typeclass corresponds to a dictionary with a single value, representing the type.
Tuplanolla 2017-02-25 05:22:50
@google scrap your haskell
lambdabot 2017-02-25 05:22:52
https://wiki.haskell.org/Scrap_your_boilerplate
ph88^ 2017-02-25 05:23:05
so am i wrong to say that this dictionary with type representation ends up in the cpu cache ?
Tuplanolla 2017-02-25 05:23:11
No, not that one.
lyxia 2017-02-25 05:23:20
ph88^: And a function with a typeclass constraint, f :: C a => f a, gets desugared into a function f :: C a -> f a (where C a is now the type of dictionaries)
Tuplanolla 2017-02-25 05:23:23
@google scrap your type classes
lambdabot 2017-02-25 05:23:25
http://www.haskellforall.com/2012/05/scrap-your-type-classes.html
lambdabot 2017-02-25 05:23:25
Title: Haskell for all: Scrap your type classes
ph88^ 2017-02-25 05:23:30
at runtime
Tuplanolla 2017-02-25 05:23:44
Read that article, ph88.
ph88^ 2017-02-25 05:23:56
for typeclasses and dictionaries ?
ph88^ 2017-02-25 05:23:57
ok
lyxia 2017-02-25 05:24:40
well it's stored somewhere if it didn't get inlined and optimized away.
centril 2017-02-25 05:24:48
If I have data type data Expr p = = EExpr { _eHist :: XExprHist p , _eXExpr :: XExpr p } | ... where XExprHist, XExpr are type families (open)... is it possible to derive Data for this type ?
ph88^ 2017-02-25 05:24:49
that's nice, the article is quite lenghty
centril 2017-02-25 05:25:56
I have managed to derive Typeable + Generic
centril 2017-02-25 05:27:00
there is no existential quantification in the data type, it is not a GADT
lyxia 2017-02-25 05:27:23
centril: you'll probably need to use standalone deriving
centril 2017-02-25 05:27:23
lyxia: tried that, didn't work :/
ph88^ 2017-02-25 05:27:23
ok i go do some groceries and read the article when i come back
ph88^ 2017-02-25 05:27:23
thanks guys
lyxia 2017-02-25 05:27:23
but if you have Generic, do you really need Data
centril 2017-02-25 05:27:23
lyxia: everything else (Eq, Ord, Show, Read, Typeable, Generic) works
lyxia 2017-02-25 05:27:23
centril: deriving instance (Data (XExprHist p), ...) => Data (Expr p)
centril 2017-02-25 05:27:23
lyxia: not sure - I was going to use Control.Lens.Plated mostly for uniplating
lyxia 2017-02-25 05:27:23
centril: did you try with the extra constraints there ^
centril 2017-02-25 05:27:23
lyxia: sec, ill paste the code
cocreature 2017-02-25 05:27:23
how do I make a dependency conditional on the GHC version?
lpaste_ 2017-02-25 05:28:29
Centril pasted "Core.Plain" at http://lpaste.net/352967
centril 2017-02-25 05:28:36
lyxia: ^
glguy 2017-02-25 05:29:01
cocreature: with flags
centril 2017-02-25 05:29:08
(scroll to the end), also, i have ForallXE (fi :: * -> Constraint p)
glguy 2017-02-25 05:29:12
or actually
glguy 2017-02-25 05:29:58
https://github.com/ekmett/semigroups/blob/master/semigroups.cabal
glguy 2017-02-25 05:30:21
cocreature: e.g. https://github.com/ekmett/semigroups/blob/master/semigroups.cabal#L130-L131
lyxia 2017-02-25 05:30:21
centril: what's the error message
lyxia 2017-02-25 05:30:29
centril: could you paste it below
cocreature 2017-02-25 05:30:36
glguy: great, thanks!
lpaste_ 2017-02-25 05:31:29
Centril revised "Core.Plain": "Core.Plain" at http://lpaste.net/352967
centril 2017-02-25 05:31:33
lpaste_: ^
glguy 2017-02-25 05:32:11
cocreature: But it's quite rare that you should be depending on the ghc version itself
glguy 2017-02-25 05:32:21
cocreature: often you're making decisions based on the base version
lyxia 2017-02-25 05:33:35
centril: somehow it's requiring a Data p constraint
glguy 2017-02-25 05:33:39
and things look like this https://github.com/ekmett/transformers-compat/blob/master/transformers-compat.cabal
lyxia 2017-02-25 05:33:49
centril: (ForallXE Data p, Data p) => ... ?
centril 2017-02-25 05:34:28
lyxia: you're awesome <3
centril 2017-02-25 05:34:31
that fixed it
cocreature 2017-02-25 05:34:41
glguy: hm yeah I guess base makes more sense
cocreature 2017-02-25 05:34:52
although it's tempting to avoid the flag :)
glguy 2017-02-25 05:35:29
cocreature: The flag setting can be inferred by cabal, so it's not extra work for the user
cocreature 2017-02-25 05:35:45
glguy: but extra work for the person writing the cabal file, i.e. me :)
lyxia 2017-02-25 05:36:48
centril: note that it suggests to "add (Data p) to the context of" the typeclass methods. This is one way to fix it.
lyxia 2017-02-25 05:37:05
centril: (adding the constraint to the instance declaration as a whole)
lyxia 2017-02-25 05:37:58
centril: another one is to redesign the typeclass to include such a constraint, but of course this is not applicable here.
cocreature 2017-02-25 05:38:13
glguy: why are the flags in transformers-compat set to manual: True? shouldn't they be toggled automatically?
centril 2017-02-25 05:38:29
lyxia: right, ofc =)
codedmart 2017-02-25 05:39:20
If I already have a stack `ReaderT AppConfig (ExceptT ServantErr (LogM IO)) a` and I want to in one area wrap that stack with StateT. In order to lift `App` actions into this do I need to write a `MonadTrans` instance?
glguy 2017-02-25 05:40:18
cocreature: Yeah, you'd think that... I'm not sure
cocreature 2017-02-25 05:42:03
glguy: alright, I'll sak in #hackage in the hope that one of the cabal devs knows.
cocreature 2017-02-25 05:42:08
*ask