Search Haskell Channel Logs

Sunday, February 19, 2017

#haskell channel featuring lpaste_, tsahyt, lyxia, ertes, lambdabot, Phillemann,

Squarism 2017-02-18 22:45:33
ok.. better description : http://lpaste.net/352706
ongy 2017-02-18 22:48:28
I can write that thing, but it doesn't allow me to derive
lpaste_ 2017-02-18 22:49:19
ongy pasted "derive with TypeFamilies" at http://lpaste.net/352707
ongy 2017-02-18 22:49:38
(I just noticed I don't need it for what I'm doing now, but I'm still interested in it)
Squarism 2017-02-18 22:50:15
ok.. worked it out. Seems the implicit param needs to be defined in a let-in before the expression using it
lyxia 2017-02-18 22:50:20
Indeed
systadmin 2017-02-18 22:50:30
Is there a way to loop the `succ` and `pred` functions for a given number of times?
lyxia 2017-02-18 22:51:34
ongy: You must use standalone deriving.
ongy 2017-02-18 22:51:54
then I don't have to put anything on the class either way, do I?
Axman6 2017-02-18 22:52:00
systadmin: well, you can use iterate succ x !! n, and deoending on the type, that may just be x + n
lyxia 2017-02-18 22:52:43
ongy: right
lyxia 2017-02-18 22:53:47
There's no way to say that all types defined by the type family must be Show-able.
ongy 2017-02-18 22:54:13
"The constraint 'Show (Type a)' is no smaller than the instance head." so I need UndecidableInstances, fun :)
lyxia 2017-02-18 22:54:31
Indeed
ongy 2017-02-18 22:55:01
ok, thanks
tsahyt 2017-02-18 22:58:40
I need a list of successive Words for folding purposes which centers around one given word, extending k elements in both directions. [x - w .. x + w] doesn't work for w > x. For that edge case I'd like to just omit those elements, so for x = 0 and w = 4 I'd like to have [0,1,2,3,4]. What's the best way to express this?
lyxia 2017-02-18 22:59:19
max (x - w) 0 ?
tsahyt 2017-02-18 22:59:49
oh
tsahyt 2017-02-18 23:00:42
well yep that does work
lyxia 2017-02-18 23:02:42
\o/
tsahyt 2017-02-18 23:02:50
actually it doesn't work for Words
tsahyt 2017-02-18 23:03:09
because they wrap around, so x - w > 0 in that case
lyxia 2017-02-18 23:03:38
oops
tsahyt 2017-02-18 23:03:41
[max (0 - 4) 0 .. 0 + 4] :: [Word8]
tsahyt 2017-02-18 23:03:46
> [max (0 - 4) 0 .. 0 + 4] :: [Word8]
lambdabot 2017-02-18 23:03:49
[]
tsahyt 2017-02-18 23:04:28
there ought to be saturating arithmetic on words...
lyxia 2017-02-18 23:04:44
x - min x w
lyxia 2017-02-18 23:04:54
there ought to be
tsahyt 2017-02-18 23:04:58
> [0 - min 0 4 .. 0 + 4] :: [Word8]
lambdabot 2017-02-18 23:05:02
[0,1,2,3,4]
tsahyt 2017-02-18 23:05:13
I see
tsahyt 2017-02-18 23:05:57
it does fail on the other end still, but there should be something similar for that I think
lyxia 2017-02-18 23:08:58
> let x = 255 :: Word8 ; w = 42 in x + min (-x - 1) w
lambdabot 2017-02-18 23:09:02
255
tsahyt 2017-02-18 23:09:55
> let f x w = [x - min x w .. x + min w (maxBound - x)] :: [Word8] in [f 2 4, f 150 4, f 253 4]
lambdabot 2017-02-18 23:09:58
[[0,1,2,3,4,5,6],[146,147,148,149,150,151,152,153,154],[249,250,251,252,253,...
tsahyt 2017-02-18 23:10:08
> let f x w = [x - min x w .. x + min w (maxBound - x)] :: [Word8] in f 253 4
lambdabot 2017-02-18 23:10:10
[249,250,251,252,253,254,255]
Phillemann 2017-02-18 23:21:00
I'm trying to understand John De Goes' article about free monads. Say I have a HttpF functor defined as "data HttpF a = Http Request (Response -> a)", and I have a "data LoggingF = Log Text a" defined. Can I now log a request and the corresponding response?
Phillemann 2017-02-18 23:21:38
From what I gather, I'd need a function "HttpF a -> Free LoggingF ()", but in there, I can only log the request...I think.
ertes 2017-02-18 23:31:51
Phillemann: an action of the free monad over HttpF is not so much an action that makes requests and write logs, but more like a scripting language you write an interpreter for
ertes 2017-02-18 23:32:43
Phillemann: if you use the 'free' library, you can use 'wrap' and/or 'liftF' to construct the primitive actions for your HttpF-based language
Phillemann 2017-02-18 23:33:15
Okay, and the logging interpreter just logs instead of...doing stuff, so it doesn't have access to the HTTP result.
ertes 2017-02-18 23:33:51
personally i prefer to put the continuations first, because it makes working with them a lot easier: data HttpF x = Request (Response -> x) Request | Log x Text
ertes 2017-02-18 23:34:22
you have an HttpF interpreter, which could very well keep track of the responses generated so far
ertes 2017-02-18 23:34:34
there is no isolated logging interpreter
ertes 2017-02-18 23:35:58
all that said free monads are only useful, if you get some value out of the possibility to have suspendable actions together with a coroutine that handles suspensions
Phillemann 2017-02-18 23:36:27
My plan was to create a functor for the API I'm implementing, then transforming this functor to a HTTP functor and then "map" this functor to "log and actually do the requests"
ertes 2017-02-18 23:36:41
for example if you have multiple interpreters, or if you want to analyse the structure of the actions in your monadic language
ertes 2017-02-18 23:37:17
Phillemann: can you make sense of the (Free IO) monad?
Phillemann 2017-02-18 23:37:29
Well, for example, I'd like to write tests which don't actually do HTTP requests (but which may log stuff).
Phillemann 2017-02-18 23:39:07
I could simply write my API functions as "ApiInput -> IO ApiOutput", but a) this is boring, b) this prevents testing that stuff.
Phillemann 2017-02-18 23:39:58
I don't know if I understand Free very well, maybe I should read much more than John's article. :/
ertes 2017-02-18 23:42:38
Phillemann: don't read articles
ertes 2017-02-18 23:42:40
read the type!
ertes 2017-02-18 23:43:02
data Free f a = Pure a | Free (f (Free f a))
ertes 2017-02-18 23:43:10
now instantiate f = IO