2024-11-12 00:03:26 +0100 | califax | (~califax@user/califx) (Ping timeout: 260 seconds) |
2024-11-12 00:04:05 +0100 | califax | (~califax@user/califx) califx |
2024-11-12 00:05:11 +0100 | chexum | (~quassel@gateway/tor-sasl/chexum) (Ping timeout: 260 seconds) |
2024-11-12 00:05:15 +0100 | biberu | (~biberu@user/biberu) (Ping timeout: 246 seconds) |
2024-11-12 00:05:42 +0100 | chexum | (~quassel@gateway/tor-sasl/chexum) chexum |
2024-11-12 00:08:51 +0100 | falafel | (~falafel@2600:1700:99f4:2050:c99f:7c1:9343:9cff) falafel |
2024-11-12 00:19:33 +0100 | machinedgod | (~machinedg@d108-173-18-100.abhsia.telus.net) machinedgod |
2024-11-12 00:24:18 +0100 | fp | (~Thunderbi@87-92-78-48.bb.dnainternet.fi) fp |
2024-11-12 00:25:54 +0100 | acidjnk_new3 | (~acidjnk@p200300d6e7283f73010f78d8062037d2.dip0.t-ipconnect.de) (Ping timeout: 246 seconds) |
2024-11-12 00:30:26 +0100 | <fp> | Hey I'm trying to parse numbers with Parsec, and I'm a bit stuck (this is for the 48h scheme tutorial). I'm trying to parse numbers of various radix and I need to avoid accepting numbers where the first digits are valid in the radix, but later digits aren't, e.g. #b010001a. The regex for what I want is /#b[01]+\b/, but I'm struggling to work out how to implement the \b. =endBy1 binDigit (choice [removeChar <$> space, removeChar <$> symbol, |
2024-11-12 00:31:29 +0100 | <Axman6> | I think your message got cut off, last I see is "<$> symbol," |
2024-11-12 00:31:44 +0100 | <fp> | =endBy1 binDigit (choice [removeChar <$> space, removeChar <$> symbol, eof])= is almost what I want (where removeChar :: Char -> ()), but it demands the latter expression be a separator |
2024-11-12 00:32:07 +0100 | <fp> | also this removeChar thing is super hacky and feels wrong |
2024-11-12 00:32:25 +0100 | <Axman6> | so what is the a in that example string? |
2024-11-12 00:32:43 +0100 | <fp> | not =binDigit= |
2024-11-12 00:32:47 +0100 | <Axman6> | do you want #b10101foo to be valid, and parse 42 and foo? |
2024-11-12 00:32:54 +0100 | <glguy> | fp: are you sure you need to worry about it? Haskell doesn't |
2024-11-12 00:33:00 +0100 | <glguy> | > (+) 1x :: Expr |
2024-11-12 00:33:01 +0100 | <lambdabot> | 1 + x |
2024-11-12 00:33:13 +0100 | <Axman6> | D: |
2024-11-12 00:33:37 +0100 | <probie> | You probably want to reject it for a lisp |
2024-11-12 00:33:42 +0100 | <fp> | yeah |
2024-11-12 00:34:33 +0100 | <probie> | Since something like `1+` or `a+b` are normally valid identifier names |
2024-11-12 00:35:02 +0100 | <fp> | And the point here is just to learn haskell, and I think there's probably some knowledge I'm missing that would allow me to reason about this problem better |
2024-11-12 00:37:04 +0100 | <glguy> | Maybe you want https://hackage.haskell.org/package/parsec-3.1.17.0/docs/Text-Parsec-Combinator.html#v:notFollowedBy |
2024-11-12 00:37:25 +0100 | <c_wraith> | have a separate parser for each radix. Only accept characters that radix uses |
2024-11-12 00:37:29 +0100 | <glguy> | Parsec doesn't make it particularly easy to handle these cases, but it's possible |
2024-11-12 00:37:53 +0100 | falafel | (~falafel@2600:1700:99f4:2050:c99f:7c1:9343:9cff) (Quit: Leaving) |
2024-11-12 00:37:56 +0100 | sawilagar | (~sawilagar@user/sawilagar) (Ping timeout: 244 seconds) |
2024-11-12 00:38:19 +0100 | falafel | (~falafel@2600:1700:99f4:2050:c99f:7c1:9343:9cff) falafel |
2024-11-12 00:38:36 +0100 | <glguy> | Ideally you'd process your input string into lexical tokens first and then use parsec over those instead of characters |
2024-11-12 00:38:53 +0100 | <fp> | > have a separate parser for each radix. Only accept characters that radix uses |
2024-11-12 00:38:53 +0100 | <fp> | The issue is that if I have #b01234, it will parse #b01 as a valid number, and then it'll parse 1234 as a valid number |
2024-11-12 00:38:54 +0100 | <lambdabot> | error: |
2024-11-12 00:38:54 +0100 | <lambdabot> | Variable not in scope: |
2024-11-12 00:38:54 +0100 | <lambdabot> | have |
2024-11-12 00:38:59 +0100 | <glguy> | Parsec is parameterized to work over an arbitrary stream of arbitrary tokens |
2024-11-12 00:39:53 +0100 | <fp> | or 234 |
2024-11-12 00:40:23 +0100 | <c_wraith> | oh, then yeah. tokenize and parse separately |
2024-11-12 00:40:36 +0100 | <glguy> | If you're doing a lisp your tokens might be something like, '(' ')' and sequences of stuff that's delimited by whitespace |
2024-11-12 00:42:25 +0100 | <fp> | But right now I'm really just trying to get this to work against single tokens. My test string is '#b0110a', which tokenization won't help |
2024-11-12 00:43:02 +0100 | <fp> | Or will it? |
2024-11-12 00:43:12 +0100 | <glguy> | it would because you'd get "#b0110a" as a token that you'd try to process and you'd decide it needs to be a binary number literal because of the first two characters |
2024-11-12 00:43:14 +0100 | jinsun | (~jinsun@user/jinsun) (Ping timeout: 248 seconds) |
2024-11-12 00:43:22 +0100 | <glguy> | and then you'd try to turn it into one and find it had invalid characters |
2024-11-12 00:43:24 +0100 | <c_wraith> | you're fundamentally asking about a tokenizing issue |
2024-11-12 00:43:48 +0100 | <c_wraith> | You need to identify a sequence of characters as a single token, and then check that the token is valid *as a token* |
2024-11-12 00:44:08 +0100 | Tuplanolla | (~Tuplanoll@91-159-69-59.elisa-laajakaista.fi) (Ping timeout: 244 seconds) |
2024-11-12 00:44:17 +0100 | <glguy> | but if you don't want to completely rethink your design maybe spend some time looking at "notFollowedBy" and hack it together |
2024-11-12 00:48:24 +0100 | Everything | (~Everythin@46.211.220.37) (Quit: leaving) |
2024-11-12 00:48:46 +0100 | <fp> | I guess the question become, if I have it set up with tokens, how do I write the parser so that it checks if the whole token matches instead of just the beginning |
2024-11-12 00:49:20 +0100 | <glguy> | if you had it set up with tokens then that's already done |
2024-11-12 00:49:28 +0100 | <glguy> | by the thing that turned it into tokens |
2024-11-12 00:49:50 +0100 | <fp> | Sure but how did that check the whole string? |
2024-11-12 00:50:22 +0100 | <glguy> | you processed the string turning it into tokens until you got to the end of the string |
2024-11-12 00:50:44 +0100 | <glguy> | You have to write a program that processes the string using the rules you have in mind; there isn't a shortcut |
2024-11-12 00:52:43 +0100 | <glguy> | that wouldn't necessarily use parsec. If you want to do it in parsec I expect you'll have to use notFollowedBy to detect that your token ended on an OK boundary |
2024-11-12 00:54:18 +0100 | <glguy> | notFollowedBy or using lookAhead (same idea) to check that you're OK with the boundary that you ended on |
2024-11-12 00:54:39 +0100 | <glguy> | There will be some class of characters you don't mind ending on: whitespace, (, ), etc. |
2024-11-12 00:57:08 +0100 | Sgeo | (~Sgeo@user/sgeo) Sgeo |
2024-11-12 00:57:13 +0100 | <fp> | Ok I think I understand. The difference with tokens is that I'd be working with Parsec String, so errors would naturally occur for the whole token. I'd fall down to a Parsec Char just for the validation, which would bubble up. Does that sound right? |
2024-11-12 00:57:40 +0100 | <fp> | *the errors would bubble up |
2024-11-12 00:58:12 +0100 | agent314 | (~quassel@static-198-44-129-53.cust.tzulo.com) (Ping timeout: 276 seconds) |
2024-11-12 01:04:14 +0100 | fp | (~Thunderbi@87-92-78-48.bb.dnainternet.fi) (Remote host closed the connection) |
2024-11-12 01:04:26 +0100 | Lord_of_Life | (~Lord@user/lord-of-life/x-2819915) (Quit: Laa shay'a waqi'un moutlaq bale kouloun moumkine) |
2024-11-12 01:04:46 +0100 | Lord_of_Life | (~Lord@user/lord-of-life/x-2819915) Lord_of_Life |
2024-11-12 01:08:53 +0100 | <haskellbridge> | <thirdofmay18081814goya> do the fmap definitions in prelude have some for of uniqueness property? |
2024-11-12 01:09:00 +0100 | <haskellbridge> | <thirdofmay18081814goya> some form* |
2024-11-12 01:10:35 +0100 | <haskellbridge> | <thirdofmay18081814goya> cough rewording |
2024-11-12 01:10:45 +0100 | <haskellbridge> | <thirdofmay18081814goya> do the fmap definitions in prelude satisfy some sort of uniqueness property? |
2024-11-12 01:13:03 +0100 | falafel | (~falafel@2600:1700:99f4:2050:c99f:7c1:9343:9cff) (Remote host closed the connection) |
2024-11-12 01:13:22 +0100 | falafel | (~falafel@2600:1700:99f4:2050:653b:1b0b:44f2:30f1) falafel |
2024-11-12 01:19:00 +0100 | falafel | (~falafel@2600:1700:99f4:2050:653b:1b0b:44f2:30f1) (Ping timeout: 276 seconds) |
2024-11-12 01:24:39 +0100 | <Leary> | @free fmap :: (a -> b) -> F a -> F b |
2024-11-12 01:24:39 +0100 | <lambdabot> | g . h = k . f => $map_F g . fmap h = fmap k . $map_F f |
2024-11-12 01:25:07 +0100 | <Leary> | thirdofmay: Parametricity and the first functor law give you uniqueness (and the second functor law). |
2024-11-12 01:25:56 +0100 | <haskellbridge> | <thirdofmay18081814goya> hm I'll read up on that, ty!! |
2024-11-12 01:32:11 +0100 | <haskellbridge> | <thirdofmay18081814goya> Leary: is there a specific sense in which you're using "parametricity" here? getting overwhelmed by the search results |
2024-11-12 01:33:44 +0100 | <Leary> | https://en.wikipedia.org/wiki/Parametricity |
2024-11-12 01:34:36 +0100 | xff0x | (~xff0x@2405:6580:b080:900:d852:39eb:7a5e:9b9f) (Ping timeout: 276 seconds) |
2024-11-12 01:34:37 +0100 | <haskellbridge> | <thirdofmay18081814goya> fantastic ty |
2024-11-12 01:52:30 +0100 | housemate | (~housemate@146.70.66.228) (Quit: "I saw it in a tiktok video and thought that it was the most smartest answer ever." ~ AnonOps Radio [some time some place] | I AM THE DERIVATIVE I AM GOING TANGENT TO THE CURVE!) |
2024-11-12 02:00:54 +0100 | td_ | (~td@i5387091E.versanet.de) (Ping timeout: 260 seconds) |
2024-11-12 02:02:17 +0100 | td_ | (~td@i53870914.versanet.de) |
2024-11-12 02:02:30 +0100 | peterbecich | (~Thunderbi@syn-047-229-123-186.res.spectrum.com) (Ping timeout: 246 seconds) |
2024-11-12 02:23:42 +0100 | biberu | (~biberu@user/biberu) biberu |
2024-11-12 02:28:00 +0100 | AlexNoo_ | (~AlexNoo@5.139.233.174) |
2024-11-12 02:29:14 +0100 | agent314 | (~quassel@static-198-44-129-53.cust.tzulo.com) agent314 |
2024-11-12 02:31:39 +0100 | AlexNoo | (~AlexNoo@5.139.233.174) (Ping timeout: 260 seconds) |
2024-11-12 02:31:54 +0100 | xff0x | (~xff0x@fsb6a9491c.tkyc517.ap.nuro.jp) |
2024-11-12 02:43:25 +0100 | peterbecich | (~Thunderbi@syn-047-229-123-186.res.spectrum.com) peterbecich |