Search Haskell Channel Logs

Wednesday, March 1, 2017

#haskell channel featuring Zemyla, Squarism, ezyang, marvin2, monochrom, markh,

Squarism 2017-03-01 12:49:59
Ive isolated an "interface" from my threading code that isolates all interaction with the actual game. It looks as if i could make this interface "generic" as of 2 type parameters. Its just that i dont really know what is the best/easiest approach? Using generics? Using type classes? In this ( http://lpaste.net/353114 ) ive marked the 2 types that i want to parameterize with "a" and "b" and. Basically "a" == To game message, "b" == to client message.
ezyang 2017-03-01 12:50:21
generics are definitely not what you want
ezyang 2017-03-01 12:50:36
type classes could work, assuming that it is always obvious what the type parameter is
Squarism 2017-03-01 12:50:36
oh ok?
ezyang 2017-03-01 12:50:54
you might also consider using an associated type, to reduce the number of type parameters you need
ezyang 2017-03-01 12:51:18
if it is always the case that to game message uniquely determines to client message
Squarism 2017-03-01 12:51:27
ezyang, well its completely deterimined by the createGameSetupAdapter call
ezyang 2017-03-01 12:52:04
this produces some adapter type?
Squarism 2017-03-01 12:52:13
yep
Squarism 2017-03-01 12:52:20
that is parameterized by the type
Squarism 2017-03-01 12:52:28
(for that particular game)
ezyang 2017-03-01 12:52:45
so you could, say, define a separate adapter type per game
ezyang 2017-03-01 12:52:54
and then have associated types declaring the game and client message types
Squarism 2017-03-01 12:53:58
would that work even if above code would be "3rd" party?
Squarism 2017-03-01 12:54:16
in a lib of its own
ezyang 2017-03-01 12:54:36
yes
ezyang 2017-03-01 12:54:36
the third party defines the adapter type, and then writes an instance for it
ezyang 2017-03-01 12:54:36
btw, the biggest problem you might run into with this scheme is convincing GHC to specialize the dictionaries away
ezyang 2017-03-01 12:54:40
if it can't manage it, you might pay perf tax
Squarism 2017-03-01 12:56:42
ezyang, im not very experianced in haskell. Im not sure i really understand what you mean by "define a separate adapter type per game , and then have associated types declaring the game and client message types"
Squarism 2017-03-01 12:56:43
is its something you could just sketch in lpaste?
Squarism 2017-03-01 12:57:21
ive written 1 type class
ezyang 2017-03-01 12:59:15
maybe https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/type-families-and-pokemon will help
ezyang 2017-03-01 12:59:20
(haven't read)
markh 2017-03-01 13:00:34
update to my windows infinite list issue: i switch over to my linux VM. much better
Zemyla 2017-03-01 13:08:36
There should be a type class for values e for which ((->) e) is Traversable.
mpickering 2017-03-01 13:12:26
Did manual documentation upload to hackage change at some point?
mpickering 2017-03-01 13:12:33
the script I used to use no longer works
mpickering 2017-03-01 13:15:03
oh I seem to be able to use cabal upload --documentation now
mpickering 2017-03-01 13:15:09
what an innovation
lambdafan 2017-03-01 13:25:51
I'm trying to do this : (Monad m) => a -> m b -> m (a -> b)
Koterpillar 2017-03-01 13:26:18
lambdafan: did you forget some brackets somewhere?
c_wraith 2017-03-01 13:29:07
it's not implementable with the missing parens. it is implementable like that.
c_wraith 2017-03-01 13:29:24
though only trivially.
Koterpillar 2017-03-01 13:30:35
oh, right
Koterpillar 2017-03-01 13:30:42
but doesn't look interesting either way
lambdafan 2017-03-01 13:32:27
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
lambdafan 2017-03-01 13:32:39
I'm using this operator
lambdafan 2017-03-01 13:32:46
I have two monadic actions
lambdafan 2017-03-01 13:32:50
and I end up with
lambdafan 2017-03-01 13:33:15
Monad m => a -> m c
lambdafan 2017-03-01 13:33:39
but I'd like a m (a -> c)
c_wraith 2017-03-01 13:33:45
that's what the type requires
c_wraith 2017-03-01 13:33:51
that's impossible
marvin2 2017-03-01 13:34:00
is it?
c_wraith 2017-03-01 13:34:25
except for specific trivial monads like identity, yes
Koterpillar 2017-03-01 13:34:52
lambdafan: consider this value: \v -> if v then putStrLn("Was true!") else return ()
Koterpillar 2017-03-01 13:35:29
lambdafan: that's Bool -> IO (). If you get an IO (Bool -> ()) out of it, what would that do?
lambdafan 2017-03-01 13:35:48
ah that makes no sense
c_wraith 2017-03-01 13:35:52
marvin2, if it wasn't impossible, Applicative and Monad would be the same thing
monochrom 2017-03-01 13:36:49
Nice example, Koterpillar.
c_wraith 2017-03-01 13:38:17
Koterpillar, yes, that really is an excellent illustration.
Koterpillar 2017-03-01 13:38:51
well, I was confused in the first place <_<
c_wraith 2017-03-01 13:39:08
you recovered well. :)