last day (462 days later) » 

2:05 PM
okey so
I wrote this
newtype Glisha us a = UnsafeGlisha { runGlisha :: GlishaInner us a }
instance Monad (Glisha us) where
    return = UnsafeGlisha . return
    (UnsafeGlisha m) >>= k = UnsafeGlisha $ m >>= runGlisha . k
and I've just realized I don't understand it
 
2:21 PM
@BartekBanachewicz Try changing the equation for return to just UnsafeRIO.
 
λ instance Monad RIO where return = UnsafeRIO ; (UnsafeRIO m) >>= k = UnsafeRIO $ m >>= runRIO . k

<interactive>:160:35:
    Couldn't match type `a' with `IO a'
      `a' is a rigid type variable bound by
          the type signature for return :: a -> RIO a at <interactive>:160:26
    Expected type: a -> RIO a
      Actual type: IO a -> RIO a
    In the expression: UnsafeRIO
    In an equation for `return': return = UnsafeRIO
    In the instance declaration for `Monad RIO'
λ
 
6 messages moved from Lounge<C++>
Oh, right. Hmm.
 
That’s annoying! But it makes perfect sense.
 
why not the functional programming room?
 
2:28 PM
@Jefffrey There were zero people in that room. There are three people in this room.
 
@Jefffrey because we're discussing haskell specifically?
 
It is a successful room
 
can I has owner then? :P
 
wow
 
2:29 PM
hi lrio
nice to see you here
 
if return is indeed a -> RIO a
WAIT
OH MY GOD
 
So, @BartekBanachewicz: does this monad contain IO as or as?
Oh! That means you get it!
\o/
 
@false return takes a from IO a and feeds it to UnsafeRIO to produce RIO a !!
wait no
damn it
 
Uh, sort of?
return makes IO a from a and feeds it to UnsafeRIO
 
yeah, the other way, my bad
 
2:32 PM
This isn’t really useful, though, because it means the only thing your monad can do (as far as it itself goes) is wrap things in IO that aren’t IO at all
 
a -> IO a , then IO a -> RIO a
@false well
 
What's RIO?
 
    pathOK :: FilePath -> IO Bool
    pathOK file = {- Implement some policy based on file name -}

    rioReadFile :: FilePath -> RIO String
    rioReadFile file = UnsafeRIO $ do
      ok <- pathOK file
      if ok then readFile file else return ""
@Jefffrey "restricted IO"
 
Using the typechecker for real-world safety! Yay.
 
aha! it's cool.
 
2:34 PM
@BartekBanachewicz No, I mean, where is it defined?
 
I used it in my library, but as I said I felt I lacked understanding
in Lounge<C++>, 24 mins ago, by Bartek Banachewicz
        newtype RIO a = UnsafeRIO { runRIO :: IO a }

        instance Monad RIO where
            return = UnsafeRIO . return
            (UnsafeRIO m) >>= k = UnsafeRIO $ m >>= runRIO . k
so when I create :: RIO () computation
 
Yeah, sorry, in that case it makes perfect sense
not to be able to return arbitrary IOs
 
well, what can I return anyway...
if I'm in RIO a, I can return... a
I need a concrete example
RIO Int, say, is a context of safe IO that produces an Int
 
Yes. And you can return 5 publicly.
 
okey, so that would basically end our thoughts on return
return will wrap that in something that can be run in IO () i.e. used in normal program
main = do { x <- runRIO (return 5) ; print x }
and that obviously works and prints 5
the harder part is >>= I guess
 
2:40 PM
So runRIO unwraps UnsafeRIO into IO?
 
@false mhm. It takes our safe computation and allows in to run in full, unrestricted, real world context of IO.
at least that's how I understand it.
 
Where’re you going to use this?
 
here, DrawFn is an alias for a function that runs in Glisha context (equivalent of RIO)
I've pimped it a bit, because I also provide state to the user, but that wasn't very hard
and so, the user can only run "approved" functions inside of that
 
Time to build a useful bot for this room, in Haskell
 
@false woah
@false there's this Wreq thingy for raw HTTP packets I found today, it's lens-based
 
2:56 PM
@BartekBanachewicz Raw HTTP packets? Isn’t that an oxymoron?
 
@false Probably is. For HTTP, in general.
 
Anyways, websockets are the key. I’m sure there’s a library around…
 
@false hm, I dunno. Wouldn't you rather run headless webkit and work with that?
 
It depends! Maybe.
 
or, there's Caprica Six
 
2:58 PM
But that’s not in Haskell
 
no, but it has ready-made interface. You'd just need to load the bot to node as native library
and bridge it
 
It can do that? I thought C6 ran in-browser.
Anyways, we’ll see! It’ll be fun, that’s for sure. Back in a bit.
 
3:18 PM
heh, that's clever
let loop = do
        line <- T.getLine
        unless (T.null line) $ WS.sendTextData conn line >> loop
using >> to end the loop //cc @Xeo
 
 
3 hours later…
6:15 PM
4 hours ago, by Bartek Banachewicz
can I has owner then? :P
@false ^
 
@BartekBanachewicz Mmmmmmm
Find other people, and we can have an election
 
@false @Xeo @Jefffrey @rightfold @ScarletAmaranth @R.MartinhoFernandes @FredOverflow @CatPlusPlus
@false that being said, it don't think this room will get very big very fast, and if a troll comes by and you're not around, shit's bound to happen
been there done that.
 
@BartekBanachewicz But will you be around?
Anyways, okay
You get to be an owner! Congratulations
 
6:35 PM
@false great :) thanks.
 
To be honest I feel like this room is pretty stupid.
 
@Jefffrey because we're fragmentating between FP and this?
 
The functional programming community is already small; both here on SO and out. Splitting it between "Haskell" and "Other functional programming languages", is the worst idea I've seen this month.
 
my thoughts exactly
but then again
FP room is mostly F# from what I've seen
 
But hey, I'm happy for you ownership man. :)
 
6:40 PM
you know until this room grows it really doesn't mean much :P
anyway, I was thinking about writing some haskell today
now that I actually understand my code :P
 
I'll go wherever there's an interesting discussion. I just feel like this is more of a "oh hey, I want to own a room myself" (by false) rather than an actual need for separation between the two rooms (being that this one is a subset of the other one).
@BartekBanachewicz And I've read about Transformers...
there's something that smells very bad.
 
@Jefffrey hmm?
@Jefffrey OTOH hard technical discussions don't like being cut in
 
This whole "duplicate your monad and append a T" is just wrong IMHO.
Just think about what StateT is.
 
@Jefffrey why "duplicate"? It's combine.
@Jefffrey it means "your monad, except also with state"
look at StateT a IO ()
or RWST a b c IO ()
 
@BartekBanachewicz and you need a whole new data for that?
 
6:45 PM
@Jefffrey how would you use it without a transformer?
 
I'm not saying without.
 
I'm saying that there should be a way to say: State is a monad, but can also be put into the transformer stack.
Without defining a new data structure.
 
@Jefffrey essentially State is expressed as StateT over Identity
so in a way, non-transformer State is weird
 
Don't go too fast there bartek. I'm still a newbie.
 
6:47 PM
@Jefffrey if you transform an identity monad with a transformer, you essentially get that transformer. Hence State can be expressed as StateT a Identity b
 
I see.
Makes sense.
Then there should only be State a m b and then define type State(something else) a b = State a Identity b.
I've not considered the implications of that yet.
 
so it's only the issue of naming for you?
Historically transformers appeared later than basic monads iirc.
 
No, it's an issue of duplicated data structure.
 
@Jefffrey many things in Haskell have been replaced by more generic variants over time, the old things still kept intact (for compatibility, I guess).
map was one of them IIRC
 
State and StateT, as well as any other M.. and M..T, share almost the same structure, and they are duplicated.
 
6:52 PM
Prelude Control.Monad.State Data.Traversable> :t mapM

<interactive>:1:1:
    Ambiguous occurrence `mapM'
    It could refer to either `Data.Traversable.mapM',
                             imported from `Data.Traversable'
                          or `Prelude.mapM',
                             imported from `Prelude' (and originally defined in `Control.Monad')
@Jefffrey so are those ^
 
Yeah, and I don't like it. :c
 
Discovering imperfections of Haskell isn't nice, I know :D
 
I need to learn more about this, but I feel like it can be improved by a long shot.
 
one thing is that we essentially have two monad libraries
transformers and mtl
 
What's mtl? That's a recurring name.
 
6:55 PM
@Jefffrey compared to the other monad library
 
Is Data.Traversable.mapM supposed to be the same of Prelude.mapM, just within another library?
 
@Jefffrey no, the former is more generic
Prelude Control.Monad.State Data.Traversable> :t Prelude.mapM
Prelude.mapM :: Monad m => (a -> m b) -> [a] -> m [b]
Prelude Control.Monad.State Data.Traversable> :t Data.Traversable.mapM
Data.Traversable.mapM
  :: (Monad m, Traversable t) => (a -> m b) -> t a -> m (t b)
 
Oh.
 
as you can imagine, there's an instance of list for Traversable
 
yeah, I imagined
 
6:58 PM
I am sure there are many more such changes, certainly in Lenses, at least.
 
Can you confirm that the purpose of monad transformers is to have a "stack" of "worlds" (different monads) to work with?
 
@Jefffrey in a way. I call them contexts, not worlds, but in essence, I think we mean the same.
and you use lift to traverse said stack (i.e. switch contexts)
 
So technically I could have a StateT over a IOT (or whatever it's called) over a Maybe correct?
 
or very handy liftIO to always get to the bottom, IO context (if one's present)
@Jefffrey there's no IOT.
mostly because of impurity it involves.
 
Right. Then ReaderT for the example. Is that correct?
 
7:01 PM
mhm
 
The clarification is on: you can stack more than 2 monads right?
 
type Jefffrey a = StateT Int (WriterT String (Maybe)) a
 
yeah, something like that
 
well, it gets tedious to use if you stack them too much
 
because WriterT is a monad too
 
7:04 PM
hence RWS/RWST monads
@Jefffrey mhm
 
Otherwise you wouldn't be able to stack it.
 
yep.
I use a stacked StateT for Glisha monad.
I've also made Glisha a special instance of MonadState, so that it provides only userstate to the user
hiding my private implementation data
 
@BartekBanachewicz holy cow, what is that? ReaderT, WriterT, State and ReaderT, WriterT, StateT, Traversable?
 
@Jefffrey Reader+Writer+State, with optional T at the end
Traversable doesn't have to be a monad
 
You got to be kidding me.
That's like the opposite of scalable.
 
7:07 PM
@Jefffrey Why? State models mutating state. Reader is just some constant (or a bunch of such). And Writer is the log.
you get "complete imperative package" in one monad, basically.
remember that each of them can have a bunch of values, and how you group them deteremines how you will be able to use them
 
Because you are creating a new data for every combinations of XT you can come up with.
 
and how many (global) contexts does an application usually have?
 
2-3-4, I guess. But it's not about that. I can imagine you can work with what we have know, it's just suboptimal IMHO.
 
I wouldn't say that. Technically every class you create in an OOP program defines a context as such.
 
Don't go down baby. Haskell is supposed to be better than that.
 
7:10 PM
compare class Jeff { const int cx, cy; int x, y; } to RWS { cx, cy :: Int } () { x, y :: Int }
@Jefffrey and it is! you can fine-tune the context much nicer than you do with a typical class.
also you get easy context composability via transformers, as you already know
 
You might be right.
I dunno. I have these mixed feeling now. We will see. Let me read more about them, and let's resume this discussion tomorrow, or whenever we feel like. :)
 
as a last thought, if you insist on having state, you can't not have one.
Do remember, however, that a lot of things in haskell are pure
 
@BartekBanachewicz What do you mean?
@BartekBanachewicz Pretty much everything except IO, no?
 
@Jefffrey yeah, but... I meant, how you do things. You map instead of mutating forEach, for example. (yeah I meant not only pure, but immutable, my bad)
@Jefffrey if your design involves storing data between calls, you have to store that data.
 
@BartekBanachewicz Yeah. You mean that I should stop thinking imperatively and start thinking functional. I see.
@BartekBanachewicz I see.
 
7:15 PM
@Jefffrey mhm. It's actually pretty easy to write imperative code in Haskell.
 
Hmm, I don't think so.
If you are referring to the do notation, that's a whole different matter.
 
oh, with do notation and IORefs and Lenses
@Jefffrey mostly Lenses inside of State
 
Eh. I've yet to encounter the need for them, but I can imagine the kind of code that it produces.
 
Given that state gives you the ability to express mutations and lenses gives you the power to manage "objects"
 
7:18 PM
a += b, for example :)
 
yeah
 
or, more complicated, from the linked article
fireBreath :: Point -> StateT Game IO ()
fireBreath target = do
    lift $ putStrLn "*rawr*"
    units.traversed.(around target 1.0).health -= 3
 
@BartekBanachewicz I have this difect: I just can't learn if I can't map it to something I need. I swear to god, I can read all of that with my whole focus for like 3 times and I would still don't understand a thing.
 
@Jefffrey but it's about dragons! :D (and games)
I get what you mean, though
That being said, lenses are still pretty cool even without state.
 
I didn't say "something interesting", I've said "something I need". I'll probably find the need soon, just not now. :)
 
7:21 PM
@Jefffrey I should work on Glisha a bit, and then games could be made using it :)
 
I've took a brief look at it, and I just got lost when this makeLenses'' (or something similar) went by. :P
 
@Jefffrey that's unicorn magic. (IOW it works and I'd rather not learn how at this point)
 
When I listen to myself I realize I'm super fucking lazy.
 
7:38 PM
Yeah. I've encountered forall x. once. I said "Well, fuck it. I need to learn about it". 15 minutes in, trying to understand it, I was like "Nope. Maybe another time."
 
@Jefffrey I only vaguely understand what it means
I am always like "I don't like too much extensions" and then my code has 5 or 6 of them :D
and now I broke cabal
 
Extensions are good. I couldn't live without OverloadedStrings for example.
I think they should fix that sometimes.
 
MultiParamTypeClasses and FlexibleInstances too
@Jefffrey 1st may this year was the last Haskell 2014 commitee meeting IIRC
 
@BartekBanachewicz You mean this?
 
@Jefffrey ooh. oooh
 
7:45 PM
Follow reddit_haskell, you scrub :P
 
I don't reddit.
oh it's a twitter channel <*shame*>
 
lol
I wonder where that star came from.
 
ha! I can read your removed messages ;)
@Jefffrey so many possibilities
 
Now it's pinned. Less suspects I guess.
Nice discussion.
Gotta go nao. See you later bud.
 
of course. see ya
 
 
2 hours later…
9:20 PM
okey so Haddock is cool
 
 
2 hours later…
11:30 PM
@Jefffrey Ew, bit.ly
 

  last day (462 days later) »