2025/09/24

Newest at the top

2025-09-24 12:00:22 +0200 <Enrico63> Leary, I see. In this case I just had the solution in front of me for the whole time. Let me try.
2025-09-24 12:00:21 +0200 <tomsmeding> Unhammer: whether stack is happy with that I dunno, but cabal supports that first-class
2025-09-24 12:00:03 +0200 <tomsmeding> Unhammer: it is definitely possible to have multiple libraries in one .cabal file; at most one of them will be the "main" library (headed by `library`), the others will be sublibraries (headed by `library some-name`)
2025-09-24 11:59:43 +0200 <Leary> Probably. It's a reasonable option anyway.
2025-09-24 11:59:09 +0200 <Enrico63> So you're saying that I should fire an error in case there's more than 3 words, but then I should disregard those additional words, rather than hard erroring, when doing the rest of the validation.
2025-09-24 11:59:02 +0200 <Unhammer> So as a workaround to my TH woes I can put all my tests in src/, putting them in the main library. Is it possible to have two libraries in one .cabal file? stack doesn't seem to let me build project:lib:library2, only project:lib
2025-09-24 11:58:41 +0200 <Leary> (collecting as many warnings/errors as possible from the input is kinda the point of validation)
2025-09-24 11:58:26 +0200 <Enrico63> Leary, I'm gonna try
2025-09-24 11:58:20 +0200 <tomsmeding> yeah what Leary says is the key point I think
2025-09-24 11:56:52 +0200 <Leary> Enrico63: Are you sure you don't want it to keep running?
2025-09-24 11:56:13 +0200 <tomsmeding> not sure if Validation has a function with that functionality
2025-09-24 11:56:02 +0200 <tomsmeding> I've never worked with Validation specifically, but `Validation e a -> a -> (a -> Validation e b) -> Validation e b` is implementable, I think -- where the loose 'a' argument is a default for when the first argument is a failure
2025-09-24 11:55:38 +0200 <Enrico63> Leary,  I've tried that, but I don't get, in the case of that failing, how to prevent the rest of the validation from running
2025-09-24 11:55:04 +0200 <tomsmeding> perhaps not orElse since that throws away the error if it's a failure
2025-09-24 11:54:25 +0200 <tomsmeding> oh maybe the idea is that you use `orElse`?
2025-09-24 11:54:16 +0200 <Enrico63> Yeah, I thought the same. As in, I feel like I'd need Monad for doing what is requested, but Validation is definitely not a Monad.
2025-09-24 11:54:13 +0200 <Leary> Enrico63: How about `hasThreeWords :: String -> Validation ()`?
2025-09-24 11:53:11 +0200 <Enrico63> Confirm. It is Applicative, but isn't a Monad.
2025-09-24 11:53:10 +0200 <tomsmeding> well if splitting is a partial operation (String -> Validation (String,String,String)) and parsing individual components also is (String -> Validation Arg), then you ain't gonna put them together without (>>=)
2025-09-24 11:52:22 +0200 <Enrico63> Wait... am I under the mistaken assumption that Validation is not a Monad... ? Let me check. I rember I've explicitly read it is not.
2025-09-24 11:51:35 +0200 <Enrico63> (Since it's the only exercise left in that batch, I could submit it and then lookup the solutions, but I want to understand first :( )
2025-09-24 11:51:32 +0200dhil(~dhil@5.151.29.141) dhil
2025-09-24 11:51:27 +0200 <tomsmeding> are you allowed to use (>>=) on Validation
2025-09-24 11:50:59 +0200 <Enrico63> Still produce an error via `Validation`.
2025-09-24 11:50:16 +0200 <tomsmeding> what are you supposed to do if the input string has more than 3 words?
2025-09-24 11:49:38 +0200merijn(~merijn@77.242.116.146) merijn
2025-09-24 11:49:34 +0200 <Enrico63> Yes, and that's what my current implementation of `parseThreeWords` is doing. It takes a single `String`, and gives back a `Validation (String, String, String)`.
2025-09-24 11:48:50 +0200 <__monty__> Enrico63: Don't you need to properly split the String in order to feed the correct bits to parseOp and parseIntOrVar?
2025-09-24 11:48:38 +0200 <Unhammer> hm, but what if I put the TH in a lib …
2025-09-24 11:48:05 +0200 <Unhammer> i already had that :-/
2025-09-24 11:46:58 +0200 <tomsmeding> Unhammer: it fixed some strange linking error with TH for me at some point; I think it was a different error, but who knows
2025-09-24 11:46:50 +0200 <Enrico63> With just `parseInt`, `parseVar`, `parseOp`, I know I can implement `parseExpression`, but then it lacks the check on the number of words in the input string, which should be 3.
2025-09-24 11:46:26 +0200 <tomsmeding> Unhammer: something unrelated with template haskell, but try adding `other-extension: TemplateHaskell` to the components in your cabal file that use the TemplateHaskell extension somewhere in the source files
2025-09-24 11:46:20 +0200chromoblob(~chromoblo@user/chromob1ot1c) chromoblob\0
2025-09-24 11:46:04 +0200chromoblob(~chromoblo@user/chromob1ot1c) (Remote host closed the connection)
2025-09-24 11:45:36 +0200 <Enrico63> probably `parseThreeWords` (in my first message I called it `parseExpr`, sorry) is what I've given the wrong signature to..
2025-09-24 11:45:36 +0200 <Enrico63> ```
2025-09-24 11:45:35 +0200 <Enrico63> parseExpression :: String -> Validation Expression
2025-09-24 11:45:35 +0200 <Enrico63> ```
2025-09-24 11:45:34 +0200 <Enrico63> I don't know how to implement this:
2025-09-24 11:45:34 +0200 <Enrico63> ```
2025-09-24 11:45:33 +0200 <Enrico63> parseThreeWords :: String -> Validation (String, String, String)
2025-09-24 11:45:33 +0200 <Enrico63> parseOp :: String -> Validation (Arg -> Arg -> Expression)
2025-09-24 11:45:32 +0200 <Enrico63> parseVar :: String -> Validation Arg
2025-09-24 11:45:32 +0200 <Enrico63> parseInt :: String -> Validation Arg
2025-09-24 11:45:31 +0200 <Enrico63> pure :: Applicative f => a -> f a
2025-09-24 11:45:31 +0200 <Enrico63> (<|>) :: Applicative f => f a -> f a -> f a
2025-09-24 11:45:30 +0200 <Enrico63> liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
2025-09-24 11:45:30 +0200 <Enrico63> ```
2025-09-24 11:45:29 +0200 <Enrico63> That is, given these