Search Haskell Channel Logs

Thursday, February 2, 2017

#haskell channel featuring lambdabot, raichoo, HugoDaniel, ski, tsahyt,

tsahyt 2017-02-01 22:51:11
relevant stackoverflow post http://stackoverflow.com/questions/29395265/haskell-scopedtypevariables-needed-in-pattern-matching-type-annotations
ski 2017-02-01 22:55:16
@type do x :: Int <- readLn; return (x+1)
lambdabot 2017-02-01 22:55:18
IO Int
ski 2017-02-01 22:55:19
kmelva ^
ski 2017-02-01 22:56:11
you need to enable either `PatternSignatures' or `ScopedTypeVariables', though
ski 2017-02-01 22:56:24
(oh, tsahyt said)
tsahyt 2017-02-01 22:56:45
TIL about pattern signatures
ski 2017-02-01 22:57:10
unfortunately they're being obsoleted :(
ski 2017-02-01 22:57:26
(or deprecated, at least)
raichoo 2017-02-01 22:57:42
oh?
tsahyt 2017-02-01 22:57:57
hmm, on 8.0.1 I don't see them at all
ski 2017-02-01 23:02:19
(imho, the syntax for `ScopedTypeVariables' is confusing/backwards. i preferred `PatternSignatures' to it)
HugoDaniel 2017-02-01 23:02:33
has anyone here used this: https://downloads.haskell.org/~ghc/7.0.1/docs/html/users_guide/rewrite-rules.html ?
tsahyt 2017-02-01 23:08:52
ski: what was the syntax with PatternSignatures?
ski 2017-02-01 23:20:05
tsahyt : you just put a type ascription on your pattern (either argument (or lambda or `case') pattern, or as a result signature on the definiendum (left-hand side in a definition, what is to be defined), as in `foo x y :: [a] = ..x..y..a..')
ski 2017-02-01 23:21:29
(the former case would be `foo (x :: [[a]]) y = ..x..y..a..' or `\(x :: [[a]]) -> ..x..a..' or `case ... of x :: [[a]] -> ..x..a..', also `do x :: [[a]] <- ...; ..x..a..', and presumably also in list comprehensions)
ski 2017-02-01 23:24:02
@type \xss -> [f x | xs :: [a] <- xss,let {f :: a -> [a]; f y = xs ++ y : xs},x <- xs] -- yes
lambdabot 2017-02-01 23:24:04
[[a]] -> [[a]]
ski 2017-02-01 23:24:17
@type \xss -> [f x | xs :: [a] <- xss,let {f :: b -> [b]; f y = xs ++ y : xs},x <- xs]
lambdabot 2017-02-01 23:24:19
error:
lambdabot 2017-02-01 23:24:19
• Couldn't match type 'a' with 'b'
lambdabot 2017-02-01 23:24:19
because type variable 'b' would escape its scope
tsahyt 2017-02-01 23:28:07
ski: but that also works with scoped type variables, e.g. do (x :: Int) <- readLn
ski 2017-02-01 23:31:45
tsahyt : yes, they added an exception to the scoping rules to allow this (specifically the existential case, which would be clunky otherwise)
ski 2017-02-01 23:34:40
(well, specifically needed for the existential case, i mean. but it applies also to the other cases .. but not to pattern bindings, which `PatternSignatures' doesn't cover, either)
ski 2017-02-01 23:34:45
@type \xs0 -> let xs :: [a] = xs in let f :: a -> [a]; f y = xs ++ y : xs in map f xs0
lambdabot 2017-02-01 23:34:46
error:
lambdabot 2017-02-01 23:34:46
• You cannot bind scoped type variable 'a'
lambdabot 2017-02-01 23:34:46
in a pattern binding signature
tsahyt 2017-02-01 23:37:27
so here you'd need a type signature with a forall a?
ski 2017-02-01 23:39:33
you could use `\(xs0 :: [a]) -> let xs :: [a] = xs0 in ..xs0..a..xs..'
ski 2017-02-01 23:40:30
or `let foo :: forall a. [a] -> [[a]]; foo xs0 = let xs :: [a] = xs0 in ..a..xs0..xs.. in foo', yes