davean 2017-02-27 17:45:32
ezyang: well, for example, if theres something that can be filtered, I prefer the monoid so I don't have to fiddle with all the composition by hand.
ezyang 2017-02-27 17:45:53
filtered?
davean 2017-02-27 17:46:03
like rules applied to matching things
ezyang 2017-02-27 17:46:25
oh, so like, HAdrian style https://www.microsoft.com/en-us/research/wp-content/uploads/2016/03/hadrian.pdf
davean 2017-02-27 17:46:27
if the config is just a few integers, I prefer just getting it over and done with
davean 2017-02-27 17:46:37
ezyang: yah
davean 2017-02-27 17:46:48
Thats the sort of time I clearly prefer a monoid
davean 2017-02-27 17:47:01
When its small and simple though thats just extra work for me
Forkk 2017-02-27 17:48:37
I don't understand why this is crashing
Forkk 2017-02-27 17:48:50
it's literally just `C2HSImp.peekByteOff ptr 0`
Cale 2017-02-27 17:49:05
Well, what's ptr pointing at?
Cale 2017-02-27 17:49:11
Is it a valid memory location?
Forkk 2017-02-27 17:49:26
actually I guess it's not a pointer
Cale 2017-02-27 17:49:35
hm?
Forkk 2017-02-27 17:49:43
it's whatever {# type value #} expands to in c2hs
Forkk 2017-02-27 17:49:46
hang on
Cale 2017-02-27 17:49:56
Well, it's got to be a Ptr a for some type a
Forkk 2017-02-27 17:50:00
which is ((C2HSImp.Ptr ()))
Forkk 2017-02-27 17:50:27
the value comes from a call to `value do_eval(instr* code, size_t len)`
Cale 2017-02-27 17:50:37
It has the type of being a pointer, but depending on how you obtained it, it might not be a reasonable one.
Cale 2017-02-27 17:50:46
What's value?
Forkk 2017-02-27 17:50:55
this struct: https://gist.github.com/Forkk/edc651092c8a5e30036f810273c11d4e
buttons840 2017-02-27 17:51:02
I am using trifecta to parse some input in a web app, and I want to display the trifecta errors in the web app if parsing fails, but I'm having some issues because trifecta errors contain color codes which don't play nice in browsers -- any suggestions?
Cale 2017-02-27 17:51:08
Doesn't seem like it should be a pointer
Forkk 2017-02-27 17:51:23
c2hs makes it a pointer
Forkk 2017-02-27 17:51:36
at least as far as haskell is concerned
Forkk 2017-02-27 17:51:43
which it maybe shouldn't
Forkk 2017-02-27 17:52:09
so what do I have to malloc this tiny struct or something
buttons840 2017-02-27 17:52:57
nevermind, I found that Text.PrettyPrint.ANSI.Leijen has some utility functions I can use
Forkk 2017-02-27 17:54:40
Cale: I made the eval function return a value* and that didn't fix it
Forkk 2017-02-27 17:57:42
actually now it's crashing in caS7_info :|
robertkennedy 2017-02-27 17:58:02
When the MonadFail proposal goes through, will `(fail "test" :: Either String Int) == Left "test"`?
Cale 2017-02-27 18:00:22
robertkennedy: I wouldn't imagine so
Cale 2017-02-27 18:00:39
Well, maybe
Cale 2017-02-27 18:01:10
You'd need for the instance to be instance MonadFail (Either String)
Cale 2017-02-27 18:01:32
and then Either e for generic e couldn't be made an instance of MonadFail
robertkennedy 2017-02-27 18:03:26
The first part I meant; what do you mean by the second part?
Cale 2017-02-27 18:05:13
Well, I suppose it will come down to how much code will break when it uses do-notation for Either e, for types e that are not String.
Cale 2017-02-27 18:05:44
I suppose maybe it'd be a good thing to point out that you have code there which throws exceptions
robertkennedy 2017-02-27 18:05:45
But wouldn't that code already break with MonadFail?
Cale 2017-02-27 18:05:56
Not necessarily
Cale 2017-02-27 18:06:04
We might just copy the existing functionality
Cale 2017-02-27 18:06:08
which is to say
Cale 2017-02-27 18:06:22
instance MonadFail (Either e) where fail x = error x
Cale 2017-02-27 18:06:36
But I don't know what the plan is
dolio 2017-02-27 18:07:25
Definitely wouldn't error.
dolio 2017-02-27 18:07:31
That'd be stupid.
dolio 2017-02-27 18:07:44
And we're not that stupid.
buttons840 2017-02-27 18:08:01
How would you remove a substring from a Text string? Or more broadly, how would you do a search an replace on a Text string?
davean 2017-02-27 18:10:18
buttons840: https://hackage.haskell.org/package/text-1.2.2.1/docs/Data-Text.html#v:replace
buttons840 2017-02-27 18:10:20
perhaps I should use replace in Data.Text? :)
davean 2017-02-27 18:10:24
Yes
buttons840 2017-02-27 18:11:25
lmgtfm -- let me google that for myself
davean 2017-02-27 18:12:40
Well, I'm glad you said it, because I'd had a very hard time resisting saying it :-p
robertkennedy 2017-02-27 18:13:20
For the first you can use break, for the second I use something like `fmap mconcat $ ("stringToKill" *> return "replace") <|> fmap singleton anyChar` (attoparsec), which extends easily to lists of find/replace pairs
Forkk 2017-02-27 18:13:29
even if I call malloc and return the pointer, I still get segfaults when I try to peek the pointer
Forkk 2017-02-27 18:13:51
but the C code can use the pointer just fine
ezyang 2017-02-27 18:14:09
explicit type application is SO EXCELLENT
davean 2017-02-27 18:14:12
Forkk: Have you checked the actual value of the pointer on both sides?
Forkk 2017-02-27 18:14:30
oh I think I just solved it
Forkk 2017-02-27 18:14:45
but now it's returning 1178791064 as the enum value
robertkennedy 2017-02-27 18:15:06
I forgot a many after mconcat.
Forkk 2017-02-27 18:16:05
davean: trying to do that, but printf isn't printing anything
buttons840 2017-02-27 18:16:53
robertkennedy: i think i mostly follow that, but i'm going to use `replace` in this case
robertkennedy 2017-02-27 18:18:13
I'd guess that's a better choice ;-)
buttons840 2017-02-27 18:18:42
robertkennedy: i've been using trifecta, it's nice to see that autoparsec is quite similar
robertkennedy 2017-02-27 18:24:36
Since it isn't (Either String), what is the smallest MonadFail that recovers the message?
fragamus 2017-02-27 18:39:00
ruby -e is handy for running short ruby expressions from command line --- is there something similar for ghci
jle` 2017-02-27 18:39:34
fragamus: there's ghc -e
fragamus 2017-02-27 18:40:27
I would not have expected that
fragamus 2017-02-27 18:40:31
but it works
fragamus 2017-02-27 18:40:42
ghc -e "putStrLn \"hello\""
jle` 2017-02-27 18:40:59
might be less useful in the ruby version because there's less "imported by default" in haskell/Prelude
fragamus 2017-02-27 18:41:17
takes a while to load up
davean 2017-02-27 18:41:48
yah, GHC is built for many things, small and fast isn't two of them
jle` 2017-02-27 18:41:55
i think it actually compiles it to a temporary file and runs it
fragamus 2017-02-27 18:41:59
seems like the stack ghci crowd would want this to be facile
jle` 2017-02-27 18:42:17
this isn't really a common workflow/usage of ghc tho
fragamus 2017-02-27 18:42:40
yeah but like turtle
fragamus 2017-02-27 18:43:40
I just realized that turtle can do what I want