Logs: freenode/#haskell
| 2020-10-26 20:47:17 | → | glguy_ joins (x@freenode/staff/haskell.developer.glguy) |
| 2020-10-26 20:47:17 | glguy_ | is now known as glguy |
| 2020-10-26 20:47:21 | → | justHaunted joins (~justache@unaffiliated/justache) |
| 2020-10-26 20:47:40 | × | blackdog quits (~blackdog@198.211.112.85) (Ping timeout: 246 seconds) |
| 2020-10-26 20:48:03 | <noname234234> | I have imagined product for and operation and sum for `or` operation |
| 2020-10-26 20:48:04 | → | justanotheruser joins (~justanoth@unaffiliated/justanotheruser) |
| 2020-10-26 20:48:14 | glguy | is now known as ghoulguy |
| 2020-10-26 20:48:16 | → | aldessa joins (~Hugh@host-92-21-7-179.as13285.net) |
| 2020-10-26 20:48:26 | <noname234234> | I believe my reasoning is correct |
| 2020-10-26 20:48:35 | <noname234234> | but I don't really know how would I express this in haskell |
| 2020-10-26 20:49:01 | <tomsmeding> | you managed Sum, didn't you? :) |
| 2020-10-26 20:49:02 | → | srid joins (sridmatrix@gateway/shell/matrix.org/x-mkesouyylxzbcafd) |
| 2020-10-26 20:49:20 | → | MikeD joins (ad5822ca@cpe-173-88-34-202.columbus.res.rr.com) |
| 2020-10-26 20:49:25 | → | alvinsj[m] joins (alvinsjmat@gateway/shell/matrix.org/x-vcggqutodlsvbbci) |
| 2020-10-26 20:49:38 | <tomsmeding> | though it's more natural to write: newtype Sum = Sum { getSum :: Bool } |
| 2020-10-26 20:49:44 | <tomsmeding> | instead of parametrising on a variable `a' |
| 2020-10-26 20:50:06 | → | blackdog joins (~blackdog@198.211.112.85) |
| 2020-10-26 20:50:09 | <noname234234> | https://paste.tomsmeding.com/w73fxoro |
| 2020-10-26 20:50:24 | <dminuoso> | noname234234: Your code is almost spot on, really. If you want to just "get it done", enable the extension by adding `{-# LANGUAGE FlexibleInstances #-}` to the top |
| 2020-10-26 20:50:32 | <dminuoso> | Or change the newtype like tomsmeding has suggested |
| 2020-10-26 20:50:41 | → | materialfuture[m joins (materialfu@gateway/shell/matrix.org/x-jvhencngpnxshide) |
| 2020-10-26 20:51:02 | → | jiribenes1 joins (jbjiribene@gateway/shell/matrix.org/x-fxavqhwgliqrsecu) |
| 2020-10-26 20:51:03 | → | tersetears[m] joins (tersetears@gateway/shell/matrix.org/x-njimwnsggeorbzzd) |
| 2020-10-26 20:51:09 | → | wi[m] joins (w1gzmatrix@gateway/shell/matrix.org/x-yfarknebhuzfmgwp) |
| 2020-10-26 20:51:16 | <tomsmeding> | I'd say, because this Sum data type is intended to be used only with Bool, I think, I would write it as I suggested |
| 2020-10-26 20:51:46 | → | mmynsted[m] joins (mmynstedtc@gateway/shell/matrix.org/x-zszjcyokedzkvvvw) |
| 2020-10-26 20:51:58 | → | steve[m] joins (stevetrout@gateway/shell/matrix.org/x-fkuthzdpqeujhzmp) |
| 2020-10-26 20:52:03 | <dminuoso> | (Note I didnt bother to check whether your boolean algebra is right, but oh well, that's on you :-) |
| 2020-10-26 20:52:04 | <noname234234> | so I want to understand the real issue here let me write it as I understood -> currently generic types are not supported in instance definition in haskell? sorry for `generic type` term but I see that as `a` I defined there |
| 2020-10-26 20:52:14 | <dminuoso> | noname234234: So |
| 2020-10-26 20:52:21 | → | michaelpj joins (michaelpjm@gateway/shell/matrix.org/x-oigadqxzdyumsikb) |
| 2020-10-26 20:52:23 | <dminuoso> | If we consider a general intsance declaration as: |
| 2020-10-26 20:52:35 | <tomsmeding> | dminuoso: side note: why didn't the haskell spec allow "flexible instances", so to speak? Didn't they want to mess with overlap detection algorithms? |
| 2020-10-26 20:52:36 | → | lnxw37d4 joins (lnxw37d4ma@gateway/shell/matrix.org/x-amgtuukfolghuwuq) |
| 2020-10-26 20:52:38 | <dminuoso> | instance ClassName (TypeConstructor t1 t2 t3 ...) |
| 2020-10-26 20:52:38 | → | maralorn joins (maralornma@gateway/shell/matrix.org/x-pkelfgrohvpzfolu) |
| 2020-10-26 20:52:49 | <dminuoso> | then t1, t2, t3, etc *must* only be type variables |
| 2020-10-26 20:52:59 | <dminuoso> | they may *not* be type constructors like Bool |
| 2020-10-26 20:53:18 | <noname234234> | type variable is typeclasses? |
| 2020-10-26 20:53:18 | <dminuoso> | tomsmeding: I dont know for sure, but I think there's two parts to it |
| 2020-10-26 20:53:40 | <dminuoso> | tomsmeding: For one, FlexibleInstances essentially incurs FlexibleContexts, and you can write incoherent code with that alone (see the GHC manual) |
| 2020-10-26 20:53:44 | tomsmeding | would say "type names", not "type constructors"; I've seen someone use "type constructor" where they meant "data constructor" in this channel |
| 2020-10-26 20:54:00 | <dminuoso> | Another one I've heard mentioned is that their implementation is non-trivial |
| 2020-10-26 20:54:13 | <dminuoso> | At least if you didn't know how to do it beforehand. |
| 2020-10-26 20:55:21 | <monsterchrom> | I avoid "type constructor" because people then go anal about whether Int counts, and independently whether (Either Int) counts. |
| 2020-10-26 20:55:21 | <dminuoso> | (It takes some real effort to write incoherent code with it, which is why I called it fairly benigh above) |
| 2020-10-26 20:55:46 | <dminuoso> | monsterchrom: a type constructor is something you can pattern match on in tyfams/tyinsts! |
| 2020-10-26 20:55:53 | <dminuoso> | just like data constructors can be pattern matched on in case-of |
| 2020-10-26 20:55:55 | <dminuoso> | :p |
| 2020-10-26 20:56:02 | <noname234234> | so type variable is for example `Num ` class? |
| 2020-10-26 20:56:29 | <tomsmeding> | noname234234: no, that's a class name ;) |
| 2020-10-26 20:56:36 | <tomsmeding> | it's something like `a` |
| 2020-10-26 20:56:43 | <noname234234> | ah oaky |
| 2020-10-26 20:56:53 | <tomsmeding> | like the `a` in your `newtype Sum a = Sum { getSum :: a }` |
| 2020-10-26 20:57:31 | <noname234234> | ah okay its like generic type |
| 2020-10-26 20:57:34 | <noname234234> | inother languages |
| 2020-10-26 20:57:39 | <dminuoso> | noname234234: no |
| 2020-10-26 20:57:54 | <dminuoso> | a type variable is the `a` itself, not what you can do with it |
| 2020-10-26 20:57:57 | <tomsmeding> | it's like the type parameter to a generic type/function in other languages, I guess |
| 2020-10-26 20:58:01 | <dminuoso> | % :t id |
| 2020-10-26 20:58:01 | <yahb> | dminuoso: a -> a |
| 2020-10-26 20:58:12 | <dminuoso> | noname234234: in that type signature above, the `a` is sort of like a placeholder |
| 2020-10-26 20:58:20 | <tomsmeding> | in java or c++, the T in the <>'s |
| 2020-10-26 20:58:40 | <dminuoso> | noname234234: so a type variable means "you can pick whatever you want there" |
| 2020-10-26 20:58:41 | <noname234234> | okay thank you |
| 2020-10-26 20:58:47 | <dminuoso> | Bool |
| 2020-10-26 20:58:48 | × | justHaunted quits (~justache@unaffiliated/justache) (Read error: Connection reset by peer) |
| 2020-10-26 20:58:49 | <dminuoso> | is not a type variable |
| 2020-10-26 20:58:58 | <dminuoso> | It's a concrete/particular type |
| 2020-10-26 20:59:37 | <noname234234> | aha get it |
| 2020-10-26 20:59:54 | <noname234234> | got it*, so I will now work on the example, |
| 2020-10-26 20:59:56 | <tomsmeding> | dminuoso: I don't see a mention of being able to write incoherent code with FlexibleContexts in the ghc user manual; am I looking in the wrong place? https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#extension-FlexibleContexts |
| 2020-10-26 20:59:57 | × | conal quits (~conal@2600:380:444d:d3f4:d82:fca6:5a7c:8afb) (Quit: Computer has gone to sleep.) |
| 2020-10-26 21:00:02 | × | DrGuschtel quits (~DrGuschte@84.39.116.180) () |
| 2020-10-26 21:00:11 | <dminuoso> | tomsmeding: See rules on overlap |
| 2020-10-26 21:00:34 | <tomsmeding> | including {-# OVERLAPPABLE #-} pragmas and such? I'd not say that counts |
| 2020-10-26 21:00:43 | <dminuoso> | https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#extension-FlexibleInstances |
| 2020-10-26 21:00:48 | <dminuoso> | https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#instance-overlap |
| 2020-10-26 21:01:01 | <dminuoso> | no, without overlap even |
| 2020-10-26 21:01:24 | × | mud quits (~mud@unaffiliated/kadoban) (Remote host closed the connection) |
| 2020-10-26 21:01:25 | <dminuoso> | (I think) |
| 2020-10-26 21:01:38 | × | GyroW quits (~GyroW@unaffiliated/gyrow) (Quit: Someone ate my pie) |
| 2020-10-26 21:02:06 | <dminuoso> | And, with the bug report I opened recently, there's a lot of awkwardness with typeclass instance resolution, where it's not even clear what the semantics are |
| 2020-10-26 21:02:15 | → | GyroW joins (~GyroW@ptr-48ujrfd1ztq5fjywfw3.18120a2.ip6.access.telenet.be) |
| 2020-10-26 21:02:16 | × | GyroW quits (~GyroW@ptr-48ujrfd1ztq5fjywfw3.18120a2.ip6.access.telenet.be) (Changing host) |
| 2020-10-26 21:02:16 | → | GyroW joins (~GyroW@unaffiliated/gyrow) |
| 2020-10-26 21:02:29 | <dminuoso> | if you look at the haskell report, it doesnt say anything about what context of typeclass instances mean/do |
| 2020-10-26 21:02:40 | <tomsmeding> | interesting |
| 2020-10-26 21:02:59 | <dminuoso> | tomsmeding: https://gitlab.haskell.org/ghc/ghc/-/issues/18836 |
| 2020-10-26 21:03:15 | <noname234234> | now I get this error -> `• No instance for (Semigroup Product) arising from the superclasses of an instance declaration• In the instance declaration for ‘Monoid Product’typecheck` |
| 2020-10-26 21:03:27 | <noname234234> | for this -> `-- | Monoid under multiplication.newtype Product = Product { getProduct :: Bool }instance Monoid Product where mempty = Product True Product x `mappend` Product y = Product (x && y)` |
| 2020-10-26 21:03:27 | <dminuoso> | A quick look at that note alone makes you wonder how subtle typeclass instance implementations really are. :-) |
| 2020-10-26 21:03:38 | <dminuoso> | noname234234: Ah, that might be friction due to changes in GHC Haskell |
| 2020-10-26 21:03:43 | × | britva quits (~britva@31-10-157-156.cgn.dynamic.upc.ch) (Quit: This computer has gone to sleep) |
| 2020-10-26 21:03:55 | <dminuoso> | noname234234: We split Monoid into Semigroup and Monoid, where mappend was moved into Semigroup as <> |
| 2020-10-26 21:04:13 | → | conal joins (~conal@2600:380:444d:d3f4:d82:fca6:5a7c:8afb) |
| 2020-10-26 21:04:13 | × | conal quits (~conal@2600:380:444d:d3f4:d82:fca6:5a7c:8afb) (Client Quit) |
| 2020-10-26 21:04:19 | → | invaser joins (~Thunderbi@31.148.23.125) |
| 2020-10-26 21:04:28 | <dminuoso> | So when you wrote `instance Monoid Foo where mappend = ...; mempty = ...;` you'd now write `instance Semigroup Foo where l <> r = ...; instance Monoid Foo where mempty = ...` |
| 2020-10-26 21:05:10 | <noname234234> | I have to separate these two? |
All times are in UTC.