Search Haskell Channel Logs

Friday, February 3, 2017

#haskell channel featuring wz1000, jle`, hololeap, phadej, lambdabot, Lokathor,

lyxia 2017-02-02 20:48:43
wz1000: if a = Void, you will want Right id, but if a is inhabited you will want Left someInhabitant, and this violates parametricity or something.
Xnuk 2017-02-02 21:00:11
@hoogle (\k -> k1) -> HashMap k v -> HashMap k1 v
lambdabot 2017-02-02 21:00:13
package base
lambdabot 2017-02-02 21:00:13
package bytestring
lambdabot 2017-02-02 21:00:13
package containers
Xnuk 2017-02-02 21:00:19
@hoogle (k -> k1) -> HashMap k v -> HashMap k1 v
lambdabot 2017-02-02 21:00:20
Data.HashMap.Lazy map :: (v1 -> v2) -> HashMap k v1 -> HashMap k v2
lambdabot 2017-02-02 21:00:20
Data.HashMap.Strict map :: (v1 -> v2) -> HashMap k v1 -> HashMap k v2
lambdabot 2017-02-02 21:00:20
Data.HashMap.Lazy mapWithKey :: (k -> v1 -> v2) -> HashMap k v1 -> HashMap k v2
wz1000 2017-02-02 21:00:47
jle`: it isn possible to construct a term of Pierce or
wz1000 2017-02-02 21:00:58
LEM
wz1000 2017-02-02 21:01:07
s/isn/isn't
jle` 2017-02-02 21:02:04
wz1000: yes, not in haskell
jle` 2017-02-02 21:02:27
that was the point, right?
jle` 2017-02-02 21:02:54
that's how you'd represent pierce's law or LEM in haskell's type system, but they aren't inhabited in haskell
jle` 2017-02-02 21:03:06
well, aside from bottom
jle` 2017-02-02 21:05:02
their equivalence means that if you have a value of one type, you can get a value of the other
Lokathor 2017-02-02 21:08:26
so i have an RNG
Lokathor 2017-02-02 21:08:37
and i want it to support the RandGen typeclass I guess
Lokathor 2017-02-02 21:08:52
but only if the random package is being compiled into the whole deal
Lokathor 2017-02-02 21:08:55
can the CPP do this for me?
jle` 2017-02-02 21:19:18
why not just have random be a dependency
Lokathor 2017-02-02 21:29:15
jle`, well if you don't want to pull in random, the module should keep on working
hololeap 2017-02-02 21:29:34
can someone give me a concise definition of what a monad transformer is?
Lokathor 2017-02-02 21:30:28
hololeap, a monad transformer is a type that adds the effects that are characteristic of one type to a monad of another type. For example, MaybeT adds possibly not having a value to some other type such as IO
Lokathor 2017-02-02 21:31:01
open question, https://hackage.haskell.org/package/base-4.9.1.0/docs/src/GHC.Int.html#Int32 this seems to imply that Int32 uses up a full machine word of space no matter what? or do GHC intrinsics replace this definition in actual programs?
hololeap 2017-02-02 21:31:25
Lokathor: can you give me a rough explaination of how this is accomplished?
Lokathor 2017-02-02 21:32:18
hololeap, the secret is that you can compose the lower forms of the Functor/Applicative/Monad scale, but for Monads you can only compose them if you know at least one of the two monads being composed
Lokathor 2017-02-02 21:32:51
so MaybeT adds special logic that's particular to the "Mabyness" of the situation, and leaves the rest of the logic to the monad being composed with
hololeap 2017-02-02 21:33:10
ok
Lokathor 2017-02-02 21:33:30
and StateT needs its own totally seperate definition that's particular to "having a state"
Lokathor 2017-02-02 21:33:33
and EitherT and so on
hololeap 2017-02-02 21:34:04
Lokathor: ty. that is really helpful. is Control.Monad.ST the same thing as StateT? i can't find StateT
Lokathor 2017-02-02 21:34:17
ST is absolutely not the same as StateT
phadej 2017-02-02 21:34:26
StateT is in transformers
xf000 2017-02-02 21:34:46
Is there a way to convert this to binary in haskell: http://pastebin.com/2fuwRz9t
xf000 2017-02-02 21:34:57
so ONE = 1 ZERO = 0
phadej 2017-02-02 21:34:59
hololeap: if you want to get dirty, try to write `instance (Monad m, Monad n) => Monad (Compose m n) where ...`
phadej 2017-02-02 21:35:19
then you'll see why transformers exist
Lokathor 2017-02-02 21:35:32
hololeap, https://hackage.haskell.org/package/transformers-0.5.2.0/docs/Control-Monad-Trans-State-Lazy.html
hololeap 2017-02-02 21:36:11
Lokathor: what is ST, because it has conversions to IO, which is what i am looking for. i want to perform IO using state, and create state using IO, iterating over each line from STDIN
Lokathor 2017-02-02 21:36:44
hololeap, ST is a special type that's (in some sense) like a restricted form of IO that doesn't interact with the world. You get the speed boost of destructive mutability, but it's kept closed in and away from outside computations
hololeap 2017-02-02 21:37:05
ok, so pretty specialized then
Lokathor 2017-02-02 21:37:13
if you want to use IO for lines with StdIn, you should look into an IORef
Lokathor 2017-02-02 21:37:15
https://hackage.haskell.org/package/base-4.6.0.1/docs/Data-IORef.html#t:IORef
Lokathor 2017-02-02 21:38:09
hololeap, yes, ST is for when you want to do things like, say, high speed vector transformations in a non-IO context
hololeap 2017-02-02 21:38:45
its essentially a card-counting program that takes in a card suit/number and then displays the current percentage of the next card meeting criteria. it displays this output after each line but needs to keep a record of each previous card to compute the statistics
Lokathor 2017-02-02 21:39:06
ah, you don't even need an IORef for that, really
Lokathor 2017-02-02 21:39:21
you can just pass the cards to the next iteration each time you loop
xf000 2017-02-02 21:39:29
Anyone?
hololeap 2017-02-02 21:39:32
it's not that i *need* it, but looking at my code, i realize i am looking to compose two different monads
hololeap 2017-02-02 21:39:54
and i'm looking for a more general way to do this
Lokathor 2017-02-02 21:40:02
xf000, this seems like a job for a text editor
hololeap 2017-02-02 21:40:18
i can post my code if that helps
xf000 2017-02-02 21:40:19
xf000: That would take a while
hololeap 2017-02-02 21:40:24
it's only 100 lines or so
Lokathor 2017-02-02 21:41:10
xf000, http://pastebin.com/VguTRNsY ?
laz 2017-02-02 21:41:22
hololeap: looks like you need StateT state IO
Lokathor 2017-02-02 21:41:25
hololeap, yes make an lpaste
xf000 2017-02-02 21:41:43
Lokathor: Howd you do that?
Lokathor 2017-02-02 21:41:57
xf000, just search and replace
hololeap 2017-02-02 21:42:16
it's a gist: https://gist.github.com/hololeap/6c75526bcb29a3dae975ce0460724780
hololeap 2017-02-02 21:43:13
the function printAll at line 99 is recursive, but i feel it could be genericized further