Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→
Page 1 .. 616 617 618 619 620 621 622 623 624 625 626 .. 5022
502,152 events total
2020-10-13 15:59:29 blip joins (58823d9e@gateway/web/cgi-irc/kiwiirc.com/ip.88.130.61.158)
2020-10-13 15:59:40 <blip> jil: it's correct, albeit unusual
2020-10-13 15:59:45 <monochrom> ski, I think s/flowing/following/
2020-10-13 15:59:51 <ski> oh
2020-10-13 16:00:01 ski sometimes fails to read typo :/
2020-10-13 16:00:15 × thir quits (~thir@p200300f27f02580060eb7dde324e54c8.dip0.t-ipconnect.de) (Ping timeout: 272 seconds)
2020-10-13 16:00:25 <blip> jil: you'd need only the top level type signature, all the other types are infered
2020-10-13 16:00:27 chenshen joins (~chenshen@2620:10d:c090:400::5:1dbd)
2020-10-13 16:00:46 × is_null quits (~jpic@pdpc/supporter/professional/is-null) (Read error: Connection reset by peer)
2020-10-13 16:00:54 <ski> @let add x y z = (x :: Int) + (y :: Int) + (z :: Int) :: Int
2020-10-13 16:00:55 <jil> sorry ski, I'm unfortunately very good at writting typos.
2020-10-13 16:00:57 <lambdabot> Defined.
2020-10-13 16:01:08 <monochrom> I trained myself to guess meanings from very large contexts when I was a child. Because I was too lazy to look up a word in a dictionary, I would rather guess an approximation from context.
2020-10-13 16:01:18 <ski> is possible, if you really want to write it like that (but it's not idiomatic, as noted)
2020-10-13 16:01:18 × chkno quits (~chkno@75-7-2-127.lightspeed.sntcca.sbcglobal.net) (Read error: Connection reset by peer)
2020-10-13 16:01:21 Rudd0 joins (~Rudd0@185.189.115.103)
2020-10-13 16:01:34 × chenshen quits (~chenshen@2620:10d:c090:400::5:1dbd) (Client Quit)
2020-10-13 16:01:53 <jil> ok. Thank you.
2020-10-13 16:02:04 chkno joins (~chkno@75-7-2-127.lightspeed.sntcca.sbcglobal.net)
2020-10-13 16:02:06 <ski> @let add (x :: Int) (y :: Int) (z :: Int) = x + y + z :: Int
2020-10-13 16:02:08 <lambdabot> Defined.
2020-10-13 16:02:09 <merijn> blip: Eh, the top level is inferred too
2020-10-13 16:02:13 <merijn> blip: Everything is inferred
2020-10-13 16:02:35 <merijn> You'll just get lynched by angry programmers if you don't annotate the top level :p
2020-10-13 16:02:40 <ski> is another, similar, way (imho looks better). but it's still unidiomatic. and this one requires a language extension (`ScopedTypeVariables')
2020-10-13 16:02:54 AlterEgo- joins (~ladew@124-198-158-163.dynamic.caiway.nl)
2020-10-13 16:03:06 <ski> add :: Int -> Int -> Int -> Int
2020-10-13 16:03:10 <ski> add x y z = x + y + z
2020-10-13 16:03:12 <jil> @let add (x :: Int) (y :: Int) = x + y
2020-10-13 16:03:14 <lambdabot> .L.hs:157:1: error:
2020-10-13 16:03:14 <lambdabot> Equations for ‘add’ have different numbers of arguments
2020-10-13 16:03:14 <lambdabot> .L.hs:157:1-55
2020-10-13 16:03:15 <ski> is the usual way to write it
2020-10-13 16:03:26 <blip> @pl \x y z -> x + y + z
2020-10-13 16:03:26 <lambdabot> ((+) .) . (+)
2020-10-13 16:03:32 <dolio> If you don't annotate the top level you're probably going to end up hating yourself, eventually.
2020-10-13 16:03:33 <ski> sorry, let me remove the earlier definition for you
2020-10-13 16:03:36 <ski> @undefine
2020-10-13 16:03:37 <lambdabot> Undefined.
2020-10-13 16:03:45 <ski> @let add (x :: Int) (y :: Int) = x + y
2020-10-13 16:03:46 <lambdabot> Defined.
2020-10-13 16:03:48 <ski> @type add
2020-10-13 16:03:49 <lambdabot> Int -> Int -> Int
2020-10-13 16:04:14 <blip> add = ((+) .) . (+) :: Int -> Int -> Int -> Int
2020-10-13 16:04:16 <blip> :P
2020-10-13 16:04:17 <jil> I see. It's clearer like that. Thank you.
2020-10-13 16:04:38 <dolio> At least if you write anything non-trivial.
2020-10-13 16:04:45 <jil> :)
2020-10-13 16:05:28 × nyd quits (~lpy@unaffiliated/elysian) (Ping timeout: 256 seconds)
2020-10-13 16:06:01 <ski> @let add (x :: Int) (y :: Int) (z :: Int) :: Int = x + y + z -- too bad this doesn't work, anymore ..
2020-10-13 16:06:01 <lambdabot> Parse failed: Cannot give an explicit type signature to a function binding
2020-10-13 16:06:40 bahamas joins (~lucian@unaffiliated/bahamas)
2020-10-13 16:07:51 <ski> jil : "more precisely I don't understand why removing the first `:: Int` make a fucntion returning `Num a` also I have x, y z Ints" -- i suppose you mean the (first) `:: Int', in the paste
2020-10-13 16:09:00 <jil> yes
2020-10-13 16:09:04 <ski> if you just say `add x y z = x + y + z', then it infers that `x',`y',`z' (and the result `x+y+z') must be of "numeric type", meaning some type that supports `+' (and a few other operations). that is what the `Num a =>' part means : works for all types `a', provided that `a' supports the `Num' operations
2020-10-13 16:09:20 <ski> @src Num
2020-10-13 16:09:20 <lambdabot> class Num a where
2020-10-13 16:09:20 <lambdabot> (+), (-), (*) :: a -> a -> a
2020-10-13 16:09:20 <lambdabot> negate, abs, signum :: a -> a
2020-10-13 16:09:20 <lambdabot> fromInteger :: Integer -> a
2020-10-13 16:10:15 aaaaaa joins (~ArthurStr@host-91-90-11-13.soborka.net)
2020-10-13 16:10:33 <jil> sure but I was understanding the `where x :: Int...` as a restriction or condition on my arguments' type
2020-10-13 16:10:34 <ski> (note that this doesn't include division. if you (also) want division, you'll have to say whether you want integral (with remainder) division, or fractional division. instead of `Num', you'd then use `Integral' or `Fractional')
2020-10-13 16:11:25 <blip> these arguments are restricted by the top level type signature
2020-10-13 16:11:37 × bahamas quits (~lucian@unaffiliated/bahamas) (Ping timeout: 264 seconds)
2020-10-13 16:11:38 pera joins (~pera@unaffiliated/pera)
2020-10-13 16:11:54 <blip> or by the return type, because the (+) forces the same type on both sides and for the result
2020-10-13 16:11:54 lucid_0x80 joins (~lucid_0x8@188.253.234.40)
2020-10-13 16:12:15 aaaaaa parts (~ArthurStr@host-91-90-11-13.soborka.net) ()
2020-10-13 16:12:18 <ski> jil : when i try the first section of code in the paste (inbetween the `{:' and the `:}'), i get errors for missing bindings (definitions) for `x',`y',`z'
2020-10-13 16:12:31 glguy is now known as ghoulguy
2020-10-13 16:12:37 <ski> (i'm not sure how you're trying this piece of code, without getting errors)
2020-10-13 16:13:22 <kuribas> is there an applicative for records? Positional arguments can be come quite unwieldy and unreadable...
2020-10-13 16:13:30 <jil> I evaluate in from org-mode in emacs that sends it to ghci
2020-10-13 16:13:38 <ski> jil : generally, if you put `someName :: SomeType', e.g. in a `where'-clause attaching to a definition, there should also be a definition of `someName' in there
2020-10-13 16:13:48 <kuribas> hmm, maybe applicative-do...
2020-10-13 16:13:49 × conal quits (~conal@64.71.133.70) (Quit: Computer has gone to sleep.)
2020-10-13 16:14:01 alp joins (~alp@2a01:e0a:58b:4920:c582:5c02:4169:5973)
2020-10-13 16:14:14 <blip> kuribas: perhaps you'd like to use lensesd
2020-10-13 16:14:17 <blip> lenses?
2020-10-13 16:14:29 <kuribas> blip: how do lenses help with applicative?
2020-10-13 16:14:39 <ski> so, i'm getting complaints, because there's no definition of `x',`y',`z', accompanying those type signatures for them, inside that `where'
2020-10-13 16:15:05 <blip> blip: to select which part of the record you'd like to act upon
2020-10-13 16:15:08 <ski> (since `x',`y',`z' are not bound in the `where', but rather in the patterns / formal parameters, to the left of the `=', in the defining equation)
2020-10-13 16:15:13 geekosaur joins (82659a0e@host154-014.vpn.uakron.edu)
2020-10-13 16:15:26 <kuribas> blip: but I need to act on all parts
2020-10-13 16:15:36 <ski> jil : hm. maybe it does something unexpected, not sure
2020-10-13 16:15:50 <blip> kuribas: well, if they are all of the same type, you can derive a functor instance
2020-10-13 16:15:57 <ski> (it being `org-mode', or perhaps some more particular mechanism invoked by it)
2020-10-13 16:16:00 <kuribas> blip: like MyRecord <$> field1 <*> field2 <*> field3
2020-10-13 16:16:07 <kuribas> but with field names instead of positions
2020-10-13 16:16:18 × xff0x quits (~fox@217.110.198.158) (Ping timeout: 256 seconds)
2020-10-13 16:16:43 <blip> kuribas: well, what about record updates?
2020-10-13 16:16:53 <kuribas> perhaps applicative do: do a <- field1; b <- field2; c <- field3; MyRecord {..}
2020-10-13 16:17:15 <kuribas> blip: record updates aren't a problem
2020-10-13 16:17:37 <kuribas> blip: my question isn't about record updates.
2020-10-13 16:17:50 <kuribas> it's about doing an applicative on a record.
2020-10-13 16:18:01 conal joins (~conal@64.71.133.70)
2020-10-13 16:18:25 <blip> well, what you propose would work (adding a pure to the last line)
2020-10-13 16:18:30 <kuribas> yeah

All times are in UTC.