Logs: freenode/#haskell
| 2020-09-20 03:59:17 | <lambdabot> | True |
| 2020-09-20 03:59:21 | <ski> | > let memb x [] = False; memb x (y:ys) | x `elem` y:ys = True | otherwise = memb x (y:ys) in memb 3 [0,2,1] |
| 2020-09-20 03:59:27 | <lambdabot> | mueval-core: Time limit exceeded |
| 2020-09-20 03:59:41 | × | gestone quits (~gestone@c-98-225-37-68.hsd1.wa.comcast.net) (Ping timeout: 256 seconds) |
| 2020-09-20 04:00:01 | <ski> | sepi : do you see why it loops ? |
| 2020-09-20 04:00:37 | → | Rudd0 joins (~Rudd0@185.189.115.118) |
| 2020-09-20 04:00:45 | <lechner> | Hi, I would like to abstract the calls to the three hash calculations in this code and get the warnings below it. Can I not include 'do' in the function? https://dpaste.com/4ZCGYR975 |
| 2020-09-20 04:00:59 | × | falafel quits (~falafel@2605:e000:1527:d491:f090:20fe:cddf:2a1a) (Remote host closed the connection) |
| 2020-09-20 04:01:25 | <sepi> | Yeah it checks if its in there, if its not it'll keep calling itself. I suppose I want to know how to stop if it reaches the end of the list |
| 2020-09-20 04:01:39 | <ski> | compute :: (Char8.ByteString -> Char8.ByteString) -> String -> Char8.ByteString |
| 2020-09-20 04:01:42 | <ski> | should be |
| 2020-09-20 04:01:43 | <ski> | compute :: (Char8.ByteString -> Char8.ByteString) -> String -> IO Char8.ByteString |
| 2020-09-20 04:02:13 | × | bitmagie quits (~Thunderbi@200116b8062b2e00fc59d02ac7bcf06a.dip.versatel-1u1.de) (Quit: bitmagie) |
| 2020-09-20 04:02:15 | <lechner> | ski: i thought the <- drops the IO? |
| 2020-09-20 04:02:17 | <ski> | sepi : make sure you take a step forward, rather than walking in place, standing still |
| 2020-09-20 04:02:19 | × | denisse quits (~spaceCat@gateway/tor-sasl/alephzer0) (Remote host closed the connection) |
| 2020-09-20 04:02:22 | <ski> | no, lechner |
| 2020-09-20 04:02:35 | → | denisse joins (~spaceCat@gateway/tor-sasl/alephzer0) |
| 2020-09-20 04:02:40 | <ski> | the whole `do'-expression will still have type `IO T', for some type `T' |
| 2020-09-20 04:02:47 | <ski> | (you can't escape) |
| 2020-09-20 04:03:40 | × | DirefulSalt quits (DirefulSal@gateway/vpn/privateinternetaccess/direfulsalt) (Remote host closed the connection) |
| 2020-09-20 04:03:50 | <ski> | btw, probably it's better to give a name to `Char8.pack contents', in order to not recompute it ? |
| 2020-09-20 04:03:59 | <ski> | (in `main', i mean) |
| 2020-09-20 04:04:09 | → | DirefulSalt joins (DirefulSal@gateway/vpn/privateinternetaccess/direfulsalt) |
| 2020-09-20 04:05:02 | <ski> | sepi : also .. if you care to tell, what is `memb' supposed to compute ? |
| 2020-09-20 04:05:15 | <lechner> | i thought perhaps the compiler would be smart enough not to, although I thought that the 'effect' from readFile may force it. |
| 2020-09-20 04:05:40 | → | mpereira joins (~mpereira@2a02:810d:f40:d96:b46b:1e98:8653:4550) |
| 2020-09-20 04:05:53 | <ski> | lechner : anyway, if you move the `readFile' out of `compute', you can probably avoid the `IO' in its return type |
| 2020-09-20 04:05:53 | × | denisse quits (~spaceCat@gateway/tor-sasl/alephzer0) (Remote host closed the connection) |
| 2020-09-20 04:06:09 | → | denisse joins (~spaceCat@gateway/tor-sasl/alephzer0) |
| 2020-09-20 04:06:22 | <lechner> | i will, but bear with me for a minute please. i changed the code the way you said, but now the code below fails even though i did not change it. |
| 2020-09-20 04:06:26 | <sepi> | like if x = ["abc", "def"]. memb says is ["def"] in x? |
| 2020-09-20 04:06:34 | <sepi> | True |
| 2020-09-20 04:06:51 | <lechner> | https://dpaste.com/553FLPZG5 |
| 2020-09-20 04:06:54 | <ski> | lechner : smart enough not to do what ? recompute the calls to `Char8.pack' ? or reread the file ? |
| 2020-09-20 04:07:03 | × | ChaiTRex quits (~ChaiTRex@gateway/tor-sasl/chaitrex) (Ping timeout: 240 seconds) |
| 2020-09-20 04:07:04 | × | toorevitimirp quits (~tooreviti@117.182.182.33) (Ping timeout: 272 seconds) |
| 2020-09-20 04:07:17 | <ski> | sepi : now try `memb "ghij" x' |
| 2020-09-20 04:07:47 | <lechner> | ski: i thought the effectful action of readFile might retrigger the remaining computation, but without that the compiler should not repack |
| 2020-09-20 04:08:14 | → | shad0w_ joins (~shad0w_@160.202.36.27) |
| 2020-09-20 04:08:16 | <ski> | GHC only does limited CSE |
| 2020-09-20 04:08:21 | → | ChaiTRex joins (~ChaiTRex@gateway/tor-sasl/chaitrex) |
| 2020-09-20 04:09:22 | <ski> | lechner : anyway, the second error message is because you still have a mistake in `compute'. but perhaps you want to keep the `IO' out of it ? |
| 2020-09-20 04:09:22 | <sepi> | It'll just sit there and I have to suspend it rather than being false |
| 2020-09-20 04:09:54 | <ski> | (in that case, it would be better to fix that first. although, if you want to, you could fix the other error) |
| 2020-09-20 04:10:02 | <ski> | sepi : and why's that ? |
| 2020-09-20 04:10:18 | <lechner> | ski: i see. sorry i misread the error message. it's my first day with Haskell |
| 2020-09-20 04:10:33 | <ski> | it's okay |
| 2020-09-20 04:10:55 | <ski> | it's not that uncommon that fixing an error in one place will trigger an error to be flagged in another location |
| 2020-09-20 04:11:29 | <ski> | sometimes it can be hard to know whether one will get out of the "tunnel(s) of error", fixing one after the other |
| 2020-09-20 04:11:40 | <ski> | with more experience, you should be able to tell this, quicker |
| 2020-09-20 04:12:12 | × | mpereira quits (~mpereira@2a02:810d:f40:d96:b46b:1e98:8653:4550) (Ping timeout: 260 seconds) |
| 2020-09-20 04:12:25 | <lechner> | ski: How do I add the IO to the result? |
| 2020-09-20 04:13:03 | <sepi> | its going to keep looking for the match because recursion, because I suppose there isn't a "if it reaches end, false" statement |
| 2020-09-20 04:13:18 | <lechner> | and why is the expected type now without the IO even though I just added it up top? |
| 2020-09-20 04:13:56 | <ski> | (this effect can also be noticed, when refactoring, changing the type signature. this can often trigger an error in other places, and fixing those can trigger further errors, like a ripple effect. this is normally a good thing, the implementation telling you all places you must fix, after having changed one place, in order to not encounter problems when running the code) |
| 2020-09-20 04:14:32 | × | elliott_ quits (~elliott@2607:fb90:18d6:fc61:a84:10d2:ef86:f415) (Ping timeout: 260 seconds) |
| 2020-09-20 04:14:52 | <lechner> | but why did it not accept the actual type without the IO in the first place. just because of the 'do'? |
| 2020-09-20 04:15:16 | <ski> | sepi : there is a "if it reaches end, false" case, that's `memb x [] = False'. the problem is that you never take a step closer to it, you're moving your legs up and down, standing still |
| 2020-09-20 04:16:04 | <ski> | lechner : "but why did it not accept the actual type without the IO in the first place. just because of the 'do'?" -- no, because of the `readFile' |
| 2020-09-20 04:16:14 | × | danso quits (~dan@107-190-41-58.cpe.teksavvy.com) (Read error: Connection reset by peer) |
| 2020-09-20 04:16:32 | <ski> | "How do I add the IO to the result?" -- result of what ? `compute' ? |
| 2020-09-20 04:16:50 | <lechner> | hashMethod $ Char8.pack contents |
| 2020-09-20 04:16:52 | → | danso joins (~dan@107-190-41-58.cpe.teksavvy.com) |
| 2020-09-20 04:17:07 | <ski> | "and why is the expected type now without the IO even though I just added it up top?" -- what do you mean ? in <https://dpaste.com/553FLPZG5>, the expected type does have an `IO' |
| 2020-09-20 04:17:20 | <ski> | lechner : `return :: a -> IO a' |
| 2020-09-20 04:17:26 | <lechner> | yes, but only because I added it up top |
| 2020-09-20 04:17:34 | → | jedws joins (~jedws@121.209.139.222) |
| 2020-09-20 04:18:06 | <lechner> | thanks. where do I place this return statement, please? and do I retain the name 'a'? |
| 2020-09-20 04:18:13 | <ski> | it's complaining that `hashMethod :: Char8.ByteString -> Char8.ByteString', while you're attempting to use it as if it was `hashMethod :: Char8.ByteString -> IO Char8.ByteString' |
| 2020-09-20 04:18:24 | <lechner> | right |
| 2020-09-20 04:18:44 | <ski> | `a' is a type variable. in your case, `a' would become `Char8.ByteString' |
| 2020-09-20 04:19:01 | <ski> | (so that you get `return :: Char8.ByteString -> IO Char8.ByteString' ..) |
| 2020-09-20 04:19:54 | → | merijn joins (~merijn@83-160-49-249.ip.xs4all.nl) |
| 2020-09-20 04:19:57 | → | drbean joins (~drbean@TC210-63-209-59.static.apol.com.tw) |
| 2020-09-20 04:20:25 | <ski> | (another way to fix the type mismatch for `hashMethod' would be to change the signature of `compute' so that the specified callback (that's `hashMethod'), actually had type `Char8.ByteString -> IO Char8.ByteString' .. but i'm not convinced you actually want to do this) |
| 2020-09-20 04:21:07 | → | Saukk joins (~Saukk@2001:998:dc:4a67:1c59:9bb5:b94c:4) |
| 2020-09-20 04:21:09 | <lechner> | I will eventually remove the IO out of that function. right now, I am just learning. Where does that return statement go, please? |
| 2020-09-20 04:21:14 | × | jedws quits (~jedws@121.209.139.222) (Client Quit) |
| 2020-09-20 04:21:29 | <lechner> | and is this thing still called a function? |
| 2020-09-20 04:21:52 | <ski> | (usually, especially as a beginner, one should think twice, before putting `IO' inside argument types. it's not that it's dangerous, but rather that it adds extra power, with possibility for extra confusion, that one relatively rarely needs) |
| 2020-09-20 04:22:01 | <ski> | `compute' ? sure |
| 2020-09-20 04:22:11 | <ski> | `hashMethod' as well |
| 2020-09-20 04:22:11 | <lechner> | i agree with that |
| 2020-09-20 04:22:34 | <lechner> | i thought perhaps the 'do' would turn compute into a monad |
| 2020-09-20 04:22:38 | <ski> | no |
| 2020-09-20 04:22:55 | <ski> | monads are not values that you deal with, at run-time |
| 2020-09-20 04:22:58 | hackage | reanimate 1.0.0.0 - Animation library based on SVGs. https://hackage.haskell.org/package/reanimate-1.0.0.0 (DavidHimmelstrup) |
| 2020-09-20 04:23:06 | <ski> | take e.g. `getLine :: IO String' |
| 2020-09-20 04:23:15 | <ski> | `getLine' is not a monad. `IO' is the monad |
| 2020-09-20 04:23:23 | <lechner> | i see. that's not a monad either |
| 2020-09-20 04:23:28 | <lechner> | or is it? |
| 2020-09-20 04:23:28 | <ski> | `getLine' is a monadic action, or just action, for short |
| 2020-09-20 04:23:35 | <ski> | if you have |
| 2020-09-20 04:23:39 | <ski> | compute :: (Char8.ByteString -> Char8.ByteString) -> String -> IO Char8.ByteString |
| 2020-09-20 04:23:43 | <lechner> | the IO is the monad? |
| 2020-09-20 04:23:57 | <ski> | then `compute hashMethod fileName' will also be an action. an `IO'-action (since `IO' is the monad here) |
| 2020-09-20 04:24:00 | <ski> | yes |
| 2020-09-20 04:24:32 | <ski> | the type `IO' (together with its instance of the `Monad' type class) is the monad |
| 2020-09-20 04:25:07 | <lechner> | okay, sorry to be persistent. in which line do i stick that return statement, please? |
All times are in UTC.