Search Haskell Channel Logs

Saturday, March 4, 2017

#haskell channel featuring lyxia, Athas, ph88, jchia_,

ph88 2017-03-04 02:48:30
anyone here familiar with GHC.Generics? it seems to me that product (fields) are encoded like this data (:*:) a b p = a p :*: b p and sum (data constructors) are encoded like this data (:+:) a b p = L1 (a p) | R1 (b p) Is there any other way to do deal with the data constructors ?
ph88 2017-03-04 02:50:13
if i have a type like data Foo = Foo1 | Bar | Foo2 and i want to find the last data constructor that starts with "Foo" i can't really do it right now, because i need lookahead. With product it's not a problem
ph88 2017-03-04 02:55:03
if it was encoded as a list consisting out of tuples of 2 elements like (elem1, (elem2, () )) then i could pattern match to get the head and the tail like (head, tail) where tail would be (elem2, ()) .. but since the head is L1 and tail is L2 i can not inspect both at the same time ..
jchia_ 2017-03-04 02:59:56
I'm trying to use Data.Vector.Sized with MonoTraversable, using "instance MonoFoldable (VS.Vector n a)" and thus getting a warning about orphan instances. If I use a newtype to wrap the VS.Vector, I can't easily use the functions that take a VS.Vector. Is there a better way to avoid the orphaned instance?
lyxia 2017-03-04 03:03:39
ph88: use overlapping instances.
ph88 2017-03-04 03:04:20
lyxia, what does that give me ?
lyxia 2017-03-04 03:05:33
ph88: actually, what exactly are you trying to do?
ph88 2017-03-04 03:06:05
i'm trying to traverse the structure and find the last occurance of a type
ph88 2017-03-04 03:06:34
structure like Foo (Wrap T) (Bar (Wrap T)) (Wrap (Qux T)) find the last T
ph88 2017-03-04 03:06:46
but actually looking at this .. i only have 1 data constructor ..
ph88 2017-03-04 03:07:03
so looks like i'm trying to solve a problem that i don't have o_O
lyxia 2017-03-04 03:07:10
By overlapping instances I mean that instance C (a :+: (b :+: c)) would be the instance for the non-last part of sum, and instance C (a :+: b) can then assume that b is not a sum, and thus is the last constructor.
lyxia 2017-03-04 03:07:31
you can actually avoid overlapping instances there because you know that b is actually a C1.
ph88 2017-03-04 03:07:54
aah very smart !
lyxia 2017-03-04 03:08:21
now you know!
ph88 2017-03-04 03:08:26
so instead of b i put C1 ?
ph88 2017-03-04 03:10:02
lyxia, actually i think i will use those overlapping instances to throw an error if my type contains multiple data constructors .. then you are not suppose to call that function on it .. do you think that is a good idea ?
Athas 2017-03-04 03:10:05
What is the meaning of semicolons at the top-level in Happy?
lyxia 2017-03-04 03:11:13
ph88: sure
ph88 2017-03-04 03:15:58
lyxia, eh actually that last thing i said is not even true .. what i need to do is inspect the value to see which data constructor was chosen i guess .. i mean ultimately i am trying to change a value to i don't need to do anything on data constructors which were not chosen. Do you know how i can find out which data constructor the value has?
ph88 2017-03-04 03:21:44
i think it will do that automatically, no? because when you convert a value to a generic representation then the data constructors which are not in the value will not be in the representation, or am i wrong ?
lyxia 2017-03-04 03:21:54
it's in the parameter of C1: C1 ('MetaCons something something)
ph88 2017-03-04 03:22:26
the name ?
lyxia 2017-03-04 03:22:27
Uh, I didn't understand your last question
lyxia 2017-03-04 03:22:40
yeah what I wrote is how you find the name of the constructor.
ph88 2017-03-04 03:24:04
i mean when i have a structure like data Foo = Foo1 | Bar | Foo2 but a value like value = Foo2 and i write a generics function for it, do i need to worry about covering other non-chosen data constructors? I think the others (Foo1, Bar) are not even in the representation ?
ph88 2017-03-04 03:24:40
in my case i don't even think that i need the name of the constructor since the operation will be the same on all the constructors ^^
ph88 2017-03-04 03:25:31
if i have like data = Foo1 (Wrap T) (Bar (Wrap T)) (Wrap (Qux T)) | Foo2 (Wrap T) (Bar (Wrap T)) no matter if it's Foo1 or Foo2 i need to change the value of the last T (they both have a last T)
lyxia 2017-03-04 03:29:03
you don't write a generic function for a particular value
lyxia 2017-03-04 03:29:59
The generic representation of Foo, Rep Foo is a sum
lyxia 2017-03-04 03:30:20
and from value will just map your constructor to one of the variants in that sum
lyxia 2017-03-04 03:31:00
but if you're writing a generic function Rep a -> X, it will need to handle all variants in one way or another
ph88 2017-03-04 03:33:19
how does that work "from value will just map your constructor to one of the variants in that sum" ?? this automatic mapping
lyxia 2017-03-04 03:35:37
from Foo1 = M1 (L1 (L1 (M1 U1))) :: (D1 _ (((C1 _ U1) :+: _) :+: _)) p
lyxia 2017-03-04 03:35:56
something like that is generated by GHC when you derive Generic.
lyxia 2017-03-04 03:36:07
(from has two other cases for Bar and Foo2 of course)
lyxia 2017-03-04 03:36:53
ph88: from is basically one direction of the isomorphism between Foo and (Either (Either () ()) ())
ph88 2017-03-04 03:38:14
aah i see .. so it only takes a part of the full representation (the other caes) ?
lyxia 2017-03-04 03:38:37
what part
lyxia 2017-03-04 03:40:43
Do you mean that Foo1 is mapped to the "branch" A in (A :+: B :+: C) and doesn't really care what's in the other two B and C? That sounds about right.
ph88 2017-03-04 03:43:45
ya