Search Haskell Channel Logs

Wednesday, March 1, 2017

#haskell channel featuring dramforever, merijn, MarcelineVQ, nate_,

nate_ 2017-03-01 02:09:40
Is there a convenient way to encode symmetric data types, whose constructors are coupled to each other?
nate_ 2017-03-01 02:09:51
E.g., data Inner = Inner1 A | Inner2 B | ... | Inner100 Z; data Outer = Outer1 Inner1 Foo | Outer2 Inner2 Bar | ... | Outer100 Inner100 Quux
nate_ 2017-03-01 02:11:15
duplicating the definitions of Inner in Outer seems fragile, just using Inner is fragile, since OuterN requires InnerN in perfect correspondance.
nate_ 2017-03-01 02:12:15
Breaking Inner into 100 individual datatypes Inner1 through Inner100 and then having a sum type Inner over them all is tedious boilerplate.
nate_ 2017-03-01 02:12:27
Is there an obvious solution to this that I'm not seeing?
merijn 2017-03-01 02:17:27
nate_: Why exactly do you have a 100 different constructors to begin with?
merijn 2017-03-01 02:17:37
That seems highly suspicious
nate_ 2017-03-01 02:18:10
I don't, it's just arbitrarily large.
nate_ 2017-03-01 02:18:31
I have 10 or maybe 20, but maybe it will change, I dunno.
merijn 2017-03-01 02:18:50
10 or 20 already sounds like a lot. Can you tell us what you're doing?
nate_ 2017-03-01 02:19:03
Abstract Syntax Tree :^/
merijn 2017-03-01 02:19:30
ok, then 10 sounds more reasonable. Why exactly do you have two separate types depending on each other, though?
merijn 2017-03-01 02:19:38
i.e. what are Inner and Outer representing
nate_ 2017-03-01 02:20:39
Two different syntactic forms of the AST
merijn 2017-03-01 02:21:30
?
nate_ 2017-03-01 02:21:48
One of the forms has extra information, but the extra info is unique to each AST node type
merijn 2017-03-01 02:22:21
nate_: Why not have a single form and have "Maybe Annotation" on every constructor?
nate_ 2017-03-01 02:23:27
Ah, good question! Because the annotated form can only occur in certain places, and I want to be able to forbid it where it cannot occur.
merijn 2017-03-01 02:23:43
nate_: Extra parameter to your AST?
nate_ 2017-03-01 02:24:15
Otherwise, everything that consumes it will either have to be a partial function or throw an error or something gross
nate_ 2017-03-01 02:24:25
So, like data AST a = ...?
merijn 2017-03-01 02:24:58
"data AST f a = MyNode Foo Bar (f Annotation)" and then use "AST Identity" for parts where you *can* have an annotation and "data Forget a = Forget" and "AST Forget" where you can't have annotations?
nate_ 2017-03-01 02:26:01
I do that elsewhere where it's a bit more uniform, I guess I hadn't considered that for this case. It's an interesting suggestion.
nate_ 2017-03-01 02:27:42
That's a bit of a Maybe at the type level, no? A little cleaner, but it would hypothetically let you parameterize it over some arbitrary f that could make no sense.
merijn 2017-03-01 02:28:17
nate_: Yes, but you can stop that by simply not exporting the "AST" type directly
merijn 2017-03-01 02:28:44
nate_: "type AnnotatedAST = AST Identity; type UnannotatedAST = AST Forget" and then only export those two
nate_ 2017-03-01 02:29:00
Granted.
nate_ 2017-03-01 02:29:26
Alright, you've convinced me! That's a good idea, at least until I'm convinced there's a better one :^)
merijn 2017-03-01 02:31:10
nate_: I'm not sure it's the most elegant solution, but it's the first thing that I can think of that avoids painful duplication :)
nate_ 2017-03-01 02:31:43
merijn: By the way, I come to this channel once every few weeks with a question, and this is probably the 5th or 6th time you've helped me; if it is not too personal to ask, do you program Haskell for a living?
merijn 2017-03-01 02:32:38
I use Haskell a lot and at work, but mostly for quick scripts not the main code
MarcelineVQ 2017-03-01 02:32:53
merijn doesn't program at all, he's from the future and his cover is that of a working programmer
nate_ 2017-03-01 02:33:39
Escaping to the past from the dystopic nightmare of a post P=NP world?
merijn 2017-03-01 02:34:02
Mostly because my main code is GPU code written in C++, so Haskell is not really suitable for that. And lots of Python plotting scripts that, as a lot of people can attest due to my complaining, I regret not writing in Haskell :p
merijn 2017-03-01 02:34:23
Honestly, rewriting most of my python to Haskell is currently a high priority task :p
MarcelineVQ 2017-03-01 02:34:39
"nanobots grey-goo'd far-future earf, the only escape was the past, her format guardian, to mend and defend..."
nate_ 2017-03-01 02:35:11
That's a riot, as I just rewrote a matlab visualization tool into matplotlib...
merijn 2017-03-01 02:35:46
nate_: I used matplotlib, because "chart (haskell library) doesn't quite have all I want yet, this'll save time!" <- should've just fixed Chart
merijn 2017-03-01 02:36:22
Then I used scikit-learn (machine learning library), because "I'm already using python and writing something from scratch and reinventing the wheel is inefficient" <- should've just reinvented the wheel
merijn 2017-03-01 02:36:34
Everyone else's wheel are shitty >.>
nate_ 2017-03-01 02:37:04
Well, their languages are dirty. so :^P
merijn 2017-03-01 02:40:01
Honestly, my day to day coding is a polyglot mess :p
nate_ 2017-03-01 02:41:44
Eh, could be worse. My philosophy is the more languages you know, the better you can think about problems in any language. Until you get to pure math, then everything else feels like it's for peasants. Which makes it hard to go back to C++. But then you remember you like food, and not dying.
dramforever 2017-03-01 02:43:59
merijn: That moment when you realize that 'saving time in the short run' does not make sense :(
merijn 2017-03-01 02:44:15
dramforever: I was hoping to save time in the long run
merijn 2017-03-01 02:44:33
dramforever: Because "these libraries are widely used, that must mean people are making them not suck"
dramforever 2017-03-01 02:45:06
Oh noooooo waaaaaay