Search Haskell Channel Logs

Wednesday, February 22, 2017

#haskell channel featuring dibblego, Wizek, Axman6, lambdabot, faberbrain, Zemyla, and 5 others.

suppi 2017-02-22 11:45:12
IsString is basically "a -> String"
suppi 2017-02-22 11:45:23
sorry: "String -> a"
suppi 2017-02-22 11:46:08
i could use show and drop the constructor name but that seems kinda bad
suppi 2017-02-22 11:47:50
oh i see there's encodeString, let me check
suppi 2017-02-22 11:48:14
yes, seems to work
suppi 2017-02-22 11:48:22
thanks
Wizek_ 2017-02-22 11:52:14
Hey! Anyone knows of a TH/QQ function that lets me declare an ADT and its Data.Default instance at once? e.g.: [withDef| data Foo = Foo {_port = 8080 :: Int, _name = def :: Maybe String }|]
Tuplanolla 2017-02-22 11:53:57
That's a nice idea, Wizek.
Axman6 2017-02-22 11:54:25
except many people believe Data.Default is a pretty flawed idea
dibblego 2017-02-22 11:54:36
o/
Wizek 2017-02-22 11:55:01
Tuplanolla, I believe so too, hoping that something exists, and if not I might take a gander at implementing it
Wizek 2017-02-22 11:55:25
Axman6, How so? And if so, do you have something superior in mind?
dibblego 2017-02-22 11:55:47
((->) t) or Monoid, depending on how it is abused
Wizek 2017-02-22 11:56:28
dibblego, So the idea itself is not flawed, but rather some instances are too broad, perhaps?
Tuplanolla 2017-02-22 11:56:30
It's often a sign of missed opportunities to use monoids, but it has its places, Wizek.
dibblego 2017-02-22 11:57:27
No, the idea is flawed, because there always exists a superior solution, which ime, is usually just "passing an argument" (e.g. reader monad) or "identity not default" (Monoid)
Axman6 2017-02-22 11:58:07
Wizek: there is a subset of haskellers who feel that classes without laws shouldn't exist, because they're usually less useful and ad hoc. Data.Default is a very good example of an ad hoc class without laws
ezyang 2017-02-22 11:58:22
this would be a good subject for a blog post!
dibblego 2017-02-22 11:58:36
Data.Default is more eggregious than just "has no laws"
ezyang 2017-02-22 11:58:39
For example, I've never been exactly sure how one is supposed to do defaults with monoids
Axman6 2017-02-22 11:58:41
If only that Edwars Yang guy would write one! :P
Axman6 2017-02-22 11:58:48
Edward*
ezyang 2017-02-22 11:58:58
:)
Zemyla 2017-02-22 11:59:12
ezyang: So what's the simplest workaround?
ezyang 2017-02-22 11:59:30
is the Monoid approach the one where you put Maybes in all your record fields?
dibblego 2017-02-22 11:59:30
I look forward to Edward Yang's new blog post!
dibblego 2017-02-22 11:59:51
no, just s/def/mempty, this is least likely
ezyang 2017-02-22 11:59:51
well, I /would/ write it if I knew what to write about :P
ezyang 2017-02-22 12:00:22
yeah, but most things don't have monoid instances that make sense here
Zemyla 2017-02-22 12:00:30
ezyang: I meant for enabling tests and benchamrks on containers.
ezyang 2017-02-22 12:00:50
Zemyla: if you call the Setup script manually you can set it up. But why do you need ti to begin with?
Zemyla 2017-02-22 12:01:08
Because I'm trying to make a change to containers.
Tuplanolla 2017-02-22 12:01:14
:t Test.QuickCheck.stdArgs -- How would you use a monoid or such for this?
lambdabot 2017-02-22 12:01:16
Args
Wizek 2017-02-22 12:01:42
^ I'm interested in that too.
dibblego 2017-02-22 12:02:25
you wouldn't, that doesn't use Data.Default, it is already done sensibly, could just use a bit of library support
ezyang 2017-02-22 12:02:25
Tuplanolla: So, the way Cabal does it is that argument records have Maybe in every field
ezyang 2017-02-22 12:03:12
and then eventually you mappend in your default record and then get everything defined
Zemyla 2017-02-22 12:03:13
I made a post in containers/issues, and wanted to try and implement my idea.
ezyang 2017-02-22 12:04:04
Zemyla: do you know how to use Setup manually?
Zemyla 2017-02-22 12:04:20
No, I don't.
ezyang 2017-02-22 12:04:25
Tuplanolla: It's a little annoying because if you want to be type safe you need to parametrize your record in Maybe/Id
Tuplanolla 2017-02-22 12:04:36
Yes, Hakyll does that too.
ezyang 2017-02-22 12:05:15
Zemyla: maybe, try
ezyang 2017-02-22 12:05:21
cabal act-as-setup -- configure
dibblego 2017-02-22 12:05:54
I have done similar to the Maybe thing, except use a type-variable and apply it as Identity or Maybe depending on requirement.
dibblego 2017-02-22 12:07:35
also this, newtype ReadFoo a = ReadFoo (Foo -> a); newtype ContFoo a = ContFoo (ReadFoo a -> a); defaults :: ContFoo a -> a
dmwit 2017-02-22 12:09:22
yeesh
ezyang 2017-02-22 12:09:44
lol
ezyang 2017-02-22 12:10:27
why isn't defaults just a ContFoo a
dmwit 2017-02-22 12:10:32
yeah
dmwit 2017-02-22 12:10:43
Also why isn't defaults just a Foo
faberbrain 2017-02-22 12:11:14
hey all, i am trying to setup some basic application "boilerplate" using a free monad + interpreter approach, but running into some crazy types and errors that i don't fully understand, and am wondering what more experienced folks think about this approach in general
faberbrain 2017-02-22 12:11:25
(i also know that is a somewhat vague description)
Zemyla 2017-02-22 12:11:34
(forall x. (a -> x) -> x) = a.
dmwit 2017-02-22 12:11:43
Also why is it bad to share the name `defaults` between libraries so that people familiar with `defaults` from other libraries can just get off the ground running without further ado
ezyang 2017-02-22 12:12:09
faberbrain: say more, or post some code :P
ezyang 2017-02-22 12:12:34
Zemyla: Sorry this is annoying, containers README really ought to have posted instructions
faberbrain 2017-02-22 12:12:57
i'd like to introduce haskell into our stack either w/ servant to devleop api endpoints, or as a background worker to replace the ruby resque stuff
dmwit 2017-02-22 12:13:01
I think it's rare to have multiple interpreters for a free monad, and therefore usually better to just define a monad rather than a free monad/interpreter pair.
faberbrain 2017-02-22 12:13:21
and so i'll need db access, queue access, and email at the very least in terms of "infra" kinds of actions
faberbrain 2017-02-22 12:14:42
so i attempted to make my free monad like this: http://lpaste.net/4554871319157538816
faberbrain 2017-02-22 12:15:07
where the "primitive" action would be like `db $ insertKey k entity` or something
dibblego 2017-02-22 12:15:56
yeah that was wrong, sorry
faberbrain 2017-02-22 12:16:28
then i could define larger application level actions on top of that like `findByEmail = db $ selectFirst [UserEmail .== "some@thing.com"] []`
faberbrain 2017-02-22 12:17:21
does this, at a conceptual/design level, make sense?
Wizek 2017-02-22 12:18:32
Asked the question here as well: https://www.reddit.com/r/haskell/comments/5vm792/anyone_knows_of_a_thqq_function_that_lets_me/ Curious if someone posts a link to a solution and/or about the discussion that arises of alternative approaches.
ezyang 2017-02-22 12:20:30
faberbrain: What free monad reference are you using?
ezyang 2017-02-22 12:21:27
Wizek: To answer your Q directly, the stynax you've written above is not valid Haskell so you'l lfirst need to write a parser for it
ezyang 2017-02-22 12:21:37
or reframe your problem so that it is valid HAskell syntax
faberbrain 2017-02-22 12:21:41
i'm using the "free" package, and loads of various blog posts etc that iv'e found describing this pattern
dmwit 2017-02-22 12:22:09
Wizek: There is `data-default-generics`
dmwit 2017-02-22 12:22:51
Wizek: But you'd need a `newtype` for `Port` or something that had a `Default` instance already.
faberbrain 2017-02-22 12:22:57
trying to find them again, there's "why free monads matter", http://dlaing.org/cofun/posts/free_and_cofree.html, http://www.haskellforall.com/2012/07/purify-code-using-free-monads.html,... and more
Wizek 2017-02-22 12:23:33
dmwit, the newtype requirement sounds sub-optimal, but good to know this exists.
dibblego 2017-02-22 12:33:13
The reason defaults :: ContFoo a is useful, is if other functions library build around ReadFoo. Of course, you have both defaults :: Foo and defaultsCont :: ContFoo a
faberbrain 2017-02-22 12:36:42
updated for some more context http://lpaste.net/4554871319157538816