Search Haskell Channel Logs

Tuesday, February 28, 2017

#haskell channel featuring MarcelineVQ, Squarism, johnw, fiddlerwoaroof, drostie, kadoban,

johnw 2017-02-28 11:45:20
Data.Map defines an operator (!) that does what you're doing
Squarism 2017-02-28 11:45:29
ah ok
Squarism 2017-02-28 11:45:58
johnw, good to know
pikajude 2017-02-28 11:47:52
Q: does Data.Map expose a way to unsafely lookup a key? A: yes !
johnw 2017-02-28 11:48:26
but maybe that's not what he meant
kadoban 2017-02-28 11:49:56
Huh, I never knew that it had a (!) actually, that could be useful sometimes. I too just use fromMaybe in such situations.
Squarism 2017-02-28 11:52:20
no.. its rather like i wanted a way to to freeze a map into a static datatype. Say i have a game of 3 players. For the rest of the game ill only lookup player 23,34,45 - and i know theyll never leave the map - so it feels moronic doing fromJust / lookup. I dont expect theres a soluton but ive been suprised before how haskell tackles problems.
pikajude 2017-02-28 11:52:25
for some reason, in the module, (!) = find and find isn't exported
pikajude 2017-02-28 11:52:30
how strange
MarcelineVQ 2017-02-28 11:53:28
which module
EvanR 2017-02-28 12:00:39
Squarism: theres a package for a "total map"
EvanR 2017-02-28 12:00:47
where lookups cant fail
johnw 2017-02-28 12:01:18
Squarism: you're thought is natural to dependently typed programming, btw
EvanR 2017-02-28 12:02:05
you can also use the type system to introduce a phantom type token that lets you use keys that are "smart" constructed along with the map, so no other keys will work
EvanR 2017-02-28 12:02:56
lookup :: k p -> Map p k a -> a
Squarism 2017-02-28 12:05:07
EvanR, oh ok. Nice to know.
EvanR 2017-02-28 12:06:05
to do it like ST, youd need a wrapper that runs your whole program in a lambda that is given the p
EvanR 2017-02-28 12:06:06
or has the p in the type
Squarism 2017-02-28 12:07:11
Maybe its a pointless bother about - it just strikes me as repeated source of irritation
EvanR 2017-02-28 12:08:04
yeah the more you become aware of these potential sources of error the more you get sucked into trying to make the system prove it impossible
EvanR 2017-02-28 12:08:08
it can get out of hand
Tuplanolla 2017-02-28 12:08:31
The first step is admitting you have a thinking problem.
johnw 2017-02-28 12:09:02
in a language like Agda, when you have a value of type "is element of list xs", it comes with a proof of how that element is a member of xs. For the map case, you'd want a constructor that shows that the map to which your key is a member, was created by inserting the asociated value at that key. This is a bit trickier to work with in Haskell, but there are ways.
fiddlerwoaroof 2017-02-28 12:11:35
Does anyone here have any recommendations for learning about the architecture of functional applications?
drostie 2017-02-28 12:13:09
My architecture for functional applications: open text file with GHCi console in Kate. Type things into GHCi until something seems to work. Paste into the text file, save. Repeat.
fiddlerwoaroof 2017-02-28 12:13:52
But, what do you think about when it comes to organizing code and choosing your abstractions?
fiddlerwoaroof 2017-02-28 12:14:04
That is, currently, more or less my process
drostie 2017-02-28 12:14:08
Results in bottom-up design which is a bit of a mess at the higher-levels but has a bunch of small functions that each get some distance towards the goal.
EvanR 2017-02-28 12:14:38
for separate sections of the program, you can use a record-of-functions(or-other-things) to specify a java-like interface
EvanR 2017-02-28 12:15:09
a value of that type is the implementation, and you can have multiple versions of the same interface (ex. for testing)
EvanR 2017-02-28 12:15:46
within each implementation you could use regular functional programming
drostie 2017-02-28 12:16:14
I mean I view abstraction choice as something for later, mostly. Occasionally I will do programming by wishful thinking where I will say, "okay, I am just going to let myself write stub functions `foo = undefined; bar = undefined; baz = undefined`, if I could cook up any functions I wanted, how would this program actually look?" -- and that comes with a bit more organization.
drostie 2017-02-28 12:17:09
Because after the main body is complete and you give the undefineds type signatures and everything typechecks, you usually start to get into more-abstract types.
EvanR 2017-02-28 12:17:25
rather than undefineds you can use holes
EvanR 2017-02-28 12:17:49
since i find it annoying to find the undefines later
drostie 2017-02-28 12:18:34
But ironically my limited experience with Haskell has been a surprising amount of *not* abstracting. It's more been that everyone else has abstracted stuff for me.
drostie 2017-02-28 12:18:51
Then again I've never published a library like lens or HXT.
Tuplanolla 2017-02-28 12:41:39
I draw lots of GraphViz diagrams (mostly data flow) and split modules with lots of imports into modules with less imports (adding type parameters as I go), drostie.
Tuplanolla 2017-02-28 12:41:56
Then architecture just happens.
Tuplanolla 2017-02-28 12:44:36
If I consciously reserve time to design an architecture, I'll just end up with lens-but-useless.