ombasa 2017-02-18 06:46:36
I want to make an abstract program which can take different read-only presets that specifies functions, e.g. a preset that specifies (*) or (+) for folding list which is a common operation throughout the program. If I use a Reader monad everything becomes monadic. Is there any disadvantage for passing around a data structure representing the preset which containing the specified functions?
Cale 2017-02-18 06:49:26
ombasa: no
ombasa 2017-02-18 06:49:43
What then is the purpose or advandage of the Reader monad?
Cale 2017-02-18 06:49:51
ombasa: apart from the few characters you'll spend on the function argument, and the fact that it will be possible to change what the argument is from various points in the program
Cale 2017-02-18 06:50:14
The reader monad *on its own* is not terribly practical
cocreature 2017-02-18 06:50:33
ombasa: you don't need to manually pass the same argument to a lot of functions
cocreature 2017-02-18 06:50:51
it's just a syntactic nicety
Cale 2017-02-18 06:50:53
But it's another way of expressing the same thing
ombasa 2017-02-18 06:51:34
Okay, so the trade off is that you don't have to pass the data structure around, but you have to do monadic computation
Cale 2017-02-18 06:51:39
Of course, if you ReaderT over something like IO, then it's also a syntactic disadvantage, to about the same degree.
the_2nd 2017-02-18 06:52:00
Has anyone sent an array of values via a from to happstack? I struggle getting it to parse properly. Can anyone help?
Tuplanolla 2017-02-18 06:52:24
I think the real benefit stems from `MonadReader` instead of `Reader` directly, ombasa.
ombasa 2017-02-18 06:54:12
`Tuplanolla` I though they where the same. What's the benefit of MonadReader compared to passing a datastructure, ignoring the extra argument?
Cale 2017-02-18 06:54:55
Well, hah, I just finished refactoring all the MonadReader constraints out of a large project so that our type errors would be sane again, so I don't think it's that either.
Tuplanolla 2017-02-18 06:55:24
With `MonadReader` you don't need to explicitly `lift` other things through it, ombasa.
Cale 2017-02-18 06:55:25
But we still use ReaderT -- it's just we use it with a custom type class instead of MonadReader
Cale 2017-02-18 06:56:13
The trouble with having large amounts of code generalised over MonadReader is that (->) e is a MonadReader instance for any type e, so if you forget an argument to a function, it confuses the shit out of GHC most of the time and you get terrible type errors.
Tuplanolla 2017-02-18 06:56:46
That's a fun one.
Cale 2017-02-18 06:56:47
(which usually occur at the level of the entire definition in which the omission applies to, rather than on the line where you missed the arg)
Welkin 2017-02-18 06:58:05
mombasa
ombasa 2017-02-18 06:58:19
yes
Cale 2017-02-18 06:58:22
So it's much better if you define your own type class with operations to get the things you want -- it looks better too, to have something like getUserToken rather than something like asks userEnvUserToken
Cale 2017-02-18 07:00:02
But then you can implement those operations for ReaderT of whatever
Cale 2017-02-18 07:00:23
The important thing is just to somehow hide the specific monad that you're using.
Cale 2017-02-18 07:01:12
(If you want extensibility in terms of the operations it supports)
ombasa 2017-02-18 07:02:22
okay so instead of passing around data Preset: cmp1=(<), cmp2=(>=) then instead implement getCmp1=(<) somewhere at top level and use it in all the deeper functions
Cale 2017-02-18 07:02:23
and the constraints on whatever monad it actually is can come from either type class constraints or from polymorphic function arguments which carry operations for some monad m -- with Reader only, that would be kinda silly though
Cale 2017-02-18 07:05:50
Well, I don't know what you're doing, but you *might* have something like class HasComparisons m where getComparison :: Ord a => m (a -> a -> Bool)
Cale 2017-02-18 07:06:06
er, I intended to do more than one operation there :)
Cale 2017-02-18 07:06:22
But whatever, you should name the class something more specific to your application anyway
Cale 2017-02-18 07:06:52
also, you might rather specify an operation which only works for a specific 'a' rather than any type 'a'
Cale 2017-02-18 07:07:11
In which case, probably the easiest thing is a functional dependency
Cale 2017-02-18 07:07:30
class HasComparison a m | m -> a where getComparison :: m (a -> a -> Bool)
Cale 2017-02-18 07:07:41
and then you might write something like
Cale 2017-02-18 07:08:16
instance Monad m => HasComparison a (ReaderT (a -> a -> Bool) m) where getComparison = ask
maksim__ 2017-02-18 07:08:21
why am i getting a cabal.config parse error here? http://pastebin.com/ZAXQUPtU
maksim__ 2017-02-18 07:08:37
Unable to parse cabal file /home/maksim/dev_projects/databrary/databrary.cabal: NoParse "other-modules" 84
maksim__ 2017-02-18 07:09:00
changing to exposed-modules gives me a different parse error
maksim__ 2017-02-18 07:09:19
Cabal file warning in /home/maksim/dev_projects/databrary/databrary.cabal: Unknown fields: exposed-modules (line 84)
Cale 2017-02-18 07:09:57
maksim__: On that line in your paste, you have other-modules, rather than exposed-modules. Are you sure you pasted the same thing?
Cale 2017-02-18 07:10:15
oh, oops
maksim__ 2017-02-18 07:10:15
Cale, i'm saying both give me a parse error, 2 different parse errors
ombasa 2017-02-18 07:10:32
exposed_modules gives me parse errors as well
Cale 2017-02-18 07:11:08
okay, is an Executable section allowed to have exposed-modules?
Cale 2017-02-18 07:11:08
I wouldn't expect that
maksim__ 2017-02-18 07:11:08
ah
maksim__ 2017-02-18 07:11:13
so why is stack warning me that not exposing those modules could lead to linker errors
ombasa 2017-02-18 07:11:25
so in a test-suite you need to list all the modules tested in 'other-modules'?
Cale 2017-02-18 07:13:18
You should list the modules under other-modules... I don't know why you're getting a parse error for that though.
Cale 2017-02-18 07:13:43
oh, I know why
Cale 2017-02-18 07:13:47
There are no commas
maksim__ 2017-02-18 07:14:02
lol
monochrom 2017-02-18 07:14:04
heh
Cale 2017-02-18 07:14:42
Databrary.Store.Config- In databrary component:
Cale 2017-02-18 07:14:51
also this
orion_ 2017-02-18 07:14:52
The darkness of humanity seeps from this bottomless pitch-black hole, the gap filled by the accumulation of the curse.
orion_ 2017-02-18 07:14:55
The darkness of humanity seeps from this bottomless pitch-black hole, the gap filled by the accumulation of the curse.
Cale 2017-02-18 07:15:02
oops
maksim__ 2017-02-18 07:15:31
Cale, i don't understand
maksim__ 2017-02-18 07:15:36
oh
maksim__ 2017-02-18 07:15:38
i see it now
Xyza 2017-02-18 07:42:28
hi