Search Haskell Channel Logs

Wednesday, March 1, 2017

#haskell channel featuring MarcelineVQ, monochrom, mniip, glguy, c_wraith, lambdabot,

threshold 2017-03-01 18:01:58
num <- newEmptyMVar ; forkIO (putMVar num 3) -- No instance for (Num GHC.Prim.Any) arising from the literal '3' In the second argument of 'putMVar', namely '3'
c_wraith 2017-03-01 18:02:47
is that from an old version of ghci?
threshold 2017-03-01 18:03:30
8.0.1
c_wraith 2017-03-01 18:03:46
ah, but it is ghci?
threshold 2017-03-01 18:03:51
c_wraith: yeah
c_wraith 2017-03-01 18:04:08
ghci doesn't get global inference.
mniip 2017-03-01 18:04:14
I could see where that's coming from
mniip 2017-03-01 18:04:19
ah right
mniip 2017-03-01 18:04:29
"num <- newEmptyMVar"
c_wraith 2017-03-01 18:04:29
yep.
mniip 2017-03-01 18:04:29
by that poiny num :: MVar Any
mniip 2017-03-01 18:04:32
point*
threshold 2017-03-01 18:05:12
I started guessing ways around this, but I wish that didn't occur. forkIO (putMVar num 3 :: Int)
threshold 2017-03-01 18:05:21
That didn't work
glguy 2017-03-01 18:05:22
does it help to add a do to the beginning?
mniip 2017-03-01 18:05:59
threshold, no like, if the two are different statements, the 'num' is bound with a wrong type already
c_wraith 2017-03-01 18:06:19
threshold, newEmptyMVar :: IO (MVar Int)
mniip 2017-03-01 18:06:49
if ghci could go back and reinfer 'num' as MVar Integer when you typed the second line...
mniip 2017-03-01 18:06:54
well nothing would make sense then
c_wraith 2017-03-01 18:07:07
threshold, the problem is that ghci wasn't implemented to read from the future to infer types.
threshold 2017-03-01 18:07:12
c_wraith: that did the trick
mniip 2017-03-01 18:07:23
although
mniip 2017-03-01 18:07:26
it could go with 'forall a. MVar a'
mniip 2017-03-01 18:07:30
but that's unsafeCoerce right there
c_wraith 2017-03-01 18:08:09
if ghci could just tell the future when type checking... so much easier.
mniip 2017-03-01 18:08:31
this issue could be avoided with representing mvars as actual sources/sinks
mniip 2017-03-01 18:08:37
but yeah, future reading
mniip 2017-03-01 18:08:42
I hear that's planned for 8.3
monochrom 2017-03-01 18:09:30
"The future is always brighter"
c_wraith 2017-03-01 18:10:06
I think glguy's suggestion should work, though.
mniip 2017-03-01 18:10:11
a monotonic function huh
c_wraith 2017-03-01 18:10:34
since it makes the two statements a single expression, so they're all type-checked together.
monochrom 2017-03-01 18:11:01
Then you need your own "return num" so you don't lose it.
c_wraith 2017-03-01 18:11:15
that's true.
monochrom 2017-03-01 18:11:25
In fact the whole "num <- do { num <- ... ... return num }"
mniip 2017-03-01 18:11:55
monochrom, but wait, it is brighter in whose frame of reference? What if we have a ghci moving relative to another ghci at 0.5c?
threshold 2017-03-01 18:12:40
let terrible = do num <- newEmptyMVar :: IO (MVar Int) ; forkIO (putMVar num 3) ; forkIO (putMVar num 4) ; v <- takeMVar num ; return v in iterate (print . terrible) 50000
threshold 2017-03-01 18:12:40
> let terrible = do num <- newEmptyMVar :: IO (MVar Int) ; forkIO (putMVar num 3) ; forkIO (putMVar num 4) ; v <- takeMVar num ; return v in iterate (print . terrible) 50000
lambdabot 2017-03-01 18:12:40
error:
lambdabot 2017-03-01 18:12:40
Not in scope: type constructor or class 'MVar'
mniip 2017-03-01 18:12:50
you can't do that
threshold 2017-03-01 18:13:10
mniip: The compiler agrees
mniip 2017-03-01 18:13:20
iterate is not the function you're looking for
mniip 2017-03-01 18:13:29
:t replicateM_
lambdabot 2017-03-01 18:13:32
Applicative m => Int -> m a -> m ()
mniip 2017-03-01 18:13:38
that's what you're looking fo
mniip 2017-03-01 18:13:46
also <$> not .
monochrom 2017-03-01 18:14:10
No, . won't do either
mniip 2017-03-01 18:14:18
that's what I said!
monochrom 2017-03-01 18:14:32
Ah. No, <$> won't do either.
mniip 2017-03-01 18:15:15
terrible :: IO Int
mniip 2017-03-01 18:15:17
lgtm?
monochrom 2017-03-01 18:15:29
@type print
lambdabot 2017-03-01 18:15:32
Show a => a -> IO ()
monochrom 2017-03-01 18:15:39
@type print . (undefined :: IO Int)
lambdabot 2017-03-01 18:15:45
error:
lambdabot 2017-03-01 18:15:45
• Couldn't match expected type 'a -> ()' with actual type 'IO Int'
lambdabot 2017-03-01 18:15:45
• In the second argument of '(.)', namely '(undefined :: IO Int)'
monochrom 2017-03-01 18:15:53
Sigh, I keep saying the wrong guy.
monochrom 2017-03-01 18:15:57
@type print <$> (undefined :: IO Int)
lambdabot 2017-03-01 18:16:03
IO (IO ())
monochrom 2017-03-01 18:16:24
Is that what you want? In fact...
monochrom 2017-03-01 18:16:32
@type replicateM_ 10 (print <$> (undefined :: IO Int))
lambdabot 2017-03-01 18:16:34
IO ()
monochrom 2017-03-01 18:17:28
OK, I guess that isn't informative.
monochrom 2017-03-01 18:17:34
This is the job of =<<
threshold 2017-03-01 18:17:34
getNum = do num <- newEmptyMVar :: IO (MVar Int) ; forkIO (putMVar num 3) ; forkIO (putMVar num 4) ; v <- takeMVar num ; return v ; main = do nums <- replicateM 50000 getNum ; mapM_ print nums
threshold 2017-03-01 18:19:27
Is there a common function similar to print which prints without attaching a new line?
threshold 2017-03-01 18:19:33
e.g. putStr
monochrom 2017-03-01 18:19:49
No, but you can combine "show" and "putStr"
threshold 2017-03-01 18:20:25
Thanks monochrom
threshold 2017-03-01 18:20:28
That worked
mniip 2017-03-01 18:24:05
oh
mniip 2017-03-01 18:24:13
oops
mniip 2017-03-01 18:24:15
right
mniip 2017-03-01 18:24:17
>>=
mniip 2017-03-01 18:24:21
Ls
mniip 2017-03-01 18:24:23
:s *
jle` 2017-03-01 18:28:22
hi
jle` 2017-03-01 18:28:29
will Profunctor ever be in base?
jle` 2017-03-01 18:29:02
i'm reading https://www.reddit.com/r/haskell/comments/3kbj9r/edward_kmett_the_unreasonable_effectiveness_of/cuwucle/ but i don't really see the real issue
mniip 2017-03-01 18:31:25
jle`, well you can see why being able to rewrite 'fmap coerce' into 'coerce' is a good idea?
jle` 2017-03-01 18:31:50
i do
mniip 2017-03-01 18:32:07
and how that is fairly tricky to do without adding unsafety
jle` 2017-03-01 18:33:08
how does profunctor cause complications in that?
mniip 2017-03-01 18:33:43
I think ed deems profunctor useless without #./.#
mniip 2017-03-01 18:33:50
and he wants a more uniform interface?
c_wraith 2017-03-01 18:34:19
not useless
threshold 2017-03-01 18:34:31
Is this the package I need to install in order to use LVars?
c_wraith 2017-03-01 18:34:33
just a massive performance regression
threshold 2017-03-01 18:34:42
Ivar
mniip 2017-03-01 18:35:05
well
mniip 2017-03-01 18:35:05
sure
mniip 2017-03-01 18:35:14
#. can be implemented in terms of rmap
mniip 2017-03-01 18:35:20
but that's "useless"
jle` 2017-03-01 18:36:20
why not have #./.# in base?
jle` 2017-03-01 18:36:28
i mean, in a hypthetical base Profunctor
mniip 2017-03-01 18:37:08
1488432829 [08:33:49] and he wants a more uniform interface?
c_wraith 2017-03-01 18:37:12
because they're not good enough for general use
c_wraith 2017-03-01 18:37:23
They're good enough for lens, but not things that use profunctors in other ways
mniip 2017-03-01 18:37:32
basiscally you'd want a similar function in Functor
mniip 2017-03-01 18:37:35
and Contravariant
mniip 2017-03-01 18:37:39
but
mniip 2017-03-01 18:37:42
more "general"
jle` 2017-03-01 18:38:39
just having them there doesn't detract from their utility, does it?
MarcelineVQ 2017-03-01 18:38:43
threshold: is what the package?
jle` 2017-03-01 18:38:44
it might be ugly
mniip 2017-03-01 18:39:40
yeah but it means more changes later
MarcelineVQ 2017-03-01 18:39:51
threshold: IVar's are from monad-par afaik http://hackage.haskell.org/package/monad-par http://chimera.labs.oreilly.com/books/1230000000929/ch04.html
mniip 2017-03-01 18:39:53
you'd want something like this resolved before adding profunctor