This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-24
Channels
- # aws (14)
- # beginners (111)
- # boot (12)
- # cider (1)
- # cljsrn (7)
- # clojure (65)
- # clojure-dusseldorf (1)
- # clojure-germany (7)
- # clojure-greece (10)
- # clojure-italy (13)
- # clojure-poland (7)
- # clojure-russia (7)
- # clojure-spec (53)
- # clojure-uk (29)
- # clojurescript (27)
- # community-development (9)
- # cursive (2)
- # data-science (1)
- # datomic (17)
- # emacs (16)
- # events (6)
- # fulcro (155)
- # graphql (8)
- # instaparse (1)
- # leiningen (30)
- # lumo (29)
- # om-next (3)
- # other-languages (46)
- # pedestal (11)
- # portkey (7)
- # re-frame (13)
- # reagent (6)
- # ring (8)
- # rum (1)
- # shadow-cljs (75)
- # sql (1)
- # timbre (3)
- # unrepl (128)
What do Haskellers mean with “IO monad is not the effect itself, but is a recipe for the effect”. Isn’t all code a recipe for making things happen?
by that logic there is no difference between a function and a partially-applied version of that function. indirection can be semantically significant (just look at transducers)
@sundarj Trying to understand what they man. What is a function of IO String different than the same function in another language that goes out in the world to fetch a string?
it is Haskell itself that then uses that to do the side-effect when you use it from the main
function
note i am not a Haskeller myself, so i could be a bit off here - but that is my understanding
ok, from a type perspective it’s pure. it’s just that Haskell implements the IO monad as effecting?
I don’t see how it helps of viewing that function as pure though. Same input, same output. Not always the case with IO or random, etc.
you could imagine replacing the IO String
with MyIO String
and the function would still work the same, right?
Purity guarantees me that I can substitute values for function calls. This is not the case with IO. So I still don’t get it.
in terms of files and http calls, you cannot gurantee referential transparency. but IO is the next best thing.. the function does not do any effects itself - it can be tested independently of whatever effect it is doing
> it can be tested independently of whatever effect it is doing Can you explain this for e.g. a function that does an HTTP request?
it's like Ring response handlers. they just return {:body "foo"}
or w/e, and then Ring itself does the grunt work
those functions can then be tested like (= (:body (handler)) "foo")
, and that is independent of the actual http request stuff
of course, monads are a little more involved than plain data, but i think the same thing applies
For example:
get :: String -> IO String
get url = simpleHTTP (getRequest url) >>= getResponseBody
You say:
> it can be tested independently of whatever effect it is doing
So, how do you test this function without doing the effect? I didn’t get that.I believe Haskell only performs IO that is used from inside the main
function. if it's not called from there, it doesn't do anything
i was under the impression that calling it outside of the main
function (or maybe the repl), did not do anything effectful
you can of course stub the function by returning some IO value, but that’s not the same as testing the function itself
@borkdude this seems to confirm what i've been saying https://stackoverflow.com/a/28639600
ok, so an IO String returned from a function is the action itself, which is always the same (because it’s some sort of reified effect), but the string may be different every time you run it… This messes with my head really.
IO String is the action itself, reified, but the outcome of the action may be different, sort of?
the edge of the system is not referentially transparent, because it interfaces with the outside world - but the things that are removed from the outside world are