Search Haskell Channel Logs

Thursday, March 9, 2017

#haskell channel featuring pacak, inferno-cop, michalrus, nilof, Jenaf, Welkin, and 7 others.

Ptival 2017-03-09 13:04:45
is there a known trick to deal with a state monad where certain parts of the code should only have read-only access to certain parts of the state?
Ptival 2017-03-09 13:04:58
seems lens-y
jle` 2017-03-09 13:05:10
Ptival: there's a common readOnly pattern
michalrus 2017-03-09 13:05:16
jle`: so that's what glguy suggested, also. (: I'll look into that, looks much more interesting than IoRef. Thank you, to both of you!
jle` 2017-03-09 13:05:17
readOnly :: Reader s a -> State s a
jle` 2017-03-09 13:05:48
and you can use 'zoom' on the result
glguy 2017-03-09 13:18:19
Ptival: Just pick an 'm' that has the behavior you want
robkennedy 2017-03-09 13:20:28
@djinn (x -> Maybe a) -> (x -> Maybe b) -> x -> Maybe (a,b)
lambdabot 2017-03-09 13:20:28
f a b c =
lambdabot 2017-03-09 13:20:28
case b c of
lambdabot 2017-03-09 13:20:28
Nothing -> Nothing
lambdabot 2017-03-09 13:20:28
Just d -> case a c of
lambdabot 2017-03-09 13:20:28
Nothing -> Nothing
lambdabot 2017-03-09 13:20:30
Just e -> Just (e, d)
glguy 2017-03-09 13:20:43
robkennedy: You can play with lambdabot in /msg
robkennedy 2017-03-09 13:21:42
Sorry. Apart from the distraction: do you know the status of DPH?
nilof 2017-03-09 13:32:29
What alternative preludes are the most used?
Welkin 2017-03-09 13:32:53
I think most people don't bother with any prelude
Welkin 2017-03-09 13:33:11
I've used classy-prelude in the past, but it is overly complex
Welkin 2017-03-09 13:33:41
all the prelude does it re-export other modules
Welkin 2017-03-09 13:33:46
is*
Jenaf 2017-03-09 13:34:16
Hi there! I'm beeing stupid right now
Jenaf 2017-03-09 13:34:35
whats the equivalent to "map" for Data.Sequence
Welkin 2017-03-09 13:34:36
is that a bee joke?
Welkin 2017-03-09 13:34:43
Jenaf: fmap
Welkin 2017-03-09 13:34:47
fmap is the generic map
Welkin 2017-03-09 13:34:48
:t fmap
lambdabot 2017-03-09 13:34:51
Functor f => (a -> b) -> f a -> f b
Jenaf 2017-03-09 13:35:09
okay, do i need to import it from traversable or so?
Koterpillar 2017-03-09 13:36:35
it is in Prelude
`Guest03 2017-03-09 13:36:57
omg
`Guest03 2017-03-09 13:37:31
why don't modules export specialized functions with standard names?
`Guest03 2017-03-09 13:37:37
like map in this case
Welkin 2017-03-09 13:37:46
?
Welkin 2017-03-09 13:37:55
fmap is the standard...
`Guest03 2017-03-09 13:37:59
map is too
Welkin 2017-03-09 13:38:02
map is the weird one that is specialized to List
`Guest03 2017-03-09 13:38:21
Data.Sequence.map would be specialized to Seq
inferno-cop 2017-03-09 13:38:25
Welkin: Does map only exist for historical reasons?
Welkin 2017-03-09 13:38:30
yes
Welkin 2017-03-09 13:38:41
fmap is what you want
`Guest03 2017-03-09 13:38:42
maybe i like to use specialized functions
`Guest03 2017-03-09 13:38:52
for extra type robustness
`Guest03 2017-03-09 13:38:55
or whatever
`Guest03 2017-03-09 13:39:04
is it so hard?
Welkin 2017-03-09 13:39:18
I assume that the 'f' stands for "Functor", as in, "functor map"
pacak 2017-03-09 13:39:22
`Guest03: Specialized functions are actually worse
pacak 2017-03-09 13:39:40
For example
pacak 2017-03-09 13:39:41
:t id
lambdabot 2017-03-09 13:39:44
a -> a
pacak 2017-03-09 13:39:56
There's only one implementation (ignoring bottoms)
pacak 2017-03-09 13:40:01
But for
pacak 2017-03-09 13:40:09
:t id (Int -> Int)
Welkin 2017-03-09 13:40:11
I have felt the pain of using specialized functions for everything when using Elm
lambdabot 2017-03-09 13:40:12
error:
lambdabot 2017-03-09 13:40:12
Pattern syntax in expression context: Int -> Int
lambdabot 2017-03-09 13:40:12
Did you mean to enable TypeApplications?
Welkin 2017-03-09 13:40:14
it sucks
pacak 2017-03-09 13:40:21
there are a whole bunch of versions
Welkin 2017-03-09 13:40:23
you have to explictly import and qualify *everything*
`Guest03 2017-03-09 13:40:28
oh well
pacak 2017-03-09 13:40:41
:t map
pacak 2017-03-09 13:40:44
:t fmap
lambdabot 2017-03-09 13:40:44
(a -> b) -> [a] -> [b]
lambdabot 2017-03-09 13:40:46
Functor f => (a -> b) -> f a -> f b
Koterpillar 2017-03-09 13:40:56
`Guest03: Elm does that, and it's a pain
`Guest03 2017-03-09 13:41:04
anyway map not only carries that, but also promise that it won't reorder and duplicate elements
pacak 2017-03-09 13:41:09
function with map's type signature can change the shape, fmap - does not.
pacak 2017-03-09 13:41:22
Not in the type signature
Welkin 2017-03-09 13:41:39
@src map
lambdabot 2017-03-09 13:41:39
map _ [] = []
lambdabot 2017-03-09 13:41:39
map f (x:xs) = f x : map f xs
Welkin 2017-03-09 13:41:43
wrong one
inferno-cop 2017-03-09 13:41:45
I think it's bad enough that there aren't general versions of collection functions like (!), insert etc
Welkin 2017-03-09 13:41:48
map is actually defined using fmap
Welkin 2017-03-09 13:41:54
so, it gives you no benefits whatsoever
Welkin 2017-03-09 13:42:34
! is only used for Vector, !! for List
Welkin 2017-03-09 13:42:42
!! is almost never used for any reason
`Guest03 2017-03-09 13:42:44
Welkin: what should i use: singleton or return?
Welkin 2017-03-09 13:42:52
because List indexing is slow
Koterpillar 2017-03-09 13:42:55
`Guest03: there's another choice, pure
Welkin 2017-03-09 13:43:00
use pure o.o
`Guest03 2017-03-09 13:43:05
or pure
`Guest03 2017-03-09 13:43:09
are you sure?
Welkin 2017-03-09 13:43:16
unless you want to be explicit and use Map.singleton
`Guest03 2017-03-09 13:43:19
what if we are deep down in layers of Applicative?
inferno-cop 2017-03-09 13:43:19
But I mean, you have Data.Map.! and Data.Array.! for example
Welkin 2017-03-09 13:43:21
that's fine
inferno-cop 2017-03-09 13:43:39
And you have to qualify them if you've got both in scope (I think?)
Welkin 2017-03-09 13:43:59
you have to qualify Vector, Array, etc almost every time anyway
Welkin 2017-03-09 13:44:06
because they share similar apis with List
Welkin 2017-03-09 13:44:10
at least Vector does
`Guest03 2017-03-09 13:44:17
Welkin: that would be V., A., ...
Welkin 2017-03-09 13:44:23
yes
Welkin 2017-03-09 13:44:30
I am not sure what your point is
inferno-cop 2017-03-09 13:44:36
Yeah, why can't we just have a Indexable typeclass or something, so we don't have to qualify
`Guest03 2017-03-09 13:44:46
i want to be explicit when i want
Welkin 2017-03-09 13:45:01
fmap comes from the Functor typeclass
`Guest03 2017-03-09 13:45:02
specialized = explicit
`Guest03 2017-03-09 13:45:42
abot the type
Welkin 2017-03-09 13:45:52
! does not have a typeclass
`Guest03 2017-03-09 13:45:52
by the way
`Guest03 2017-03-09 13:45:52
why the names ! and !! were chosen?
inferno-cop 2017-03-09 13:45:53
It doesn't, but I am saying the world may be a better place if it had a typeclass