You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi ! I've been playing around with PureScript's typing system and I've come across an example where the compiler's behaviour doesn't seem consistent.
In my experiments and as mentioned in ticket #4498, PureScript does not generalise let expressions. So why is the following code accepted by the compiler? The reasons why I think this code should not be accepted are in the comments to the following code.
moduleMainwhereimportPrelude (classShow, Unit, discard, show, (<>))
importEffect (Effect)
importEffect.Console (log)
dataLista=Nil | Consa (Lista)
instance (Showa) =>Show (Lista) where
show (Nil) = "Nil"
show (Cons hd tl) = "(Cons " <> show hd <> "" <> show tl <> ")"main::EffectUnit
main = let x = Nilin-- x :: List τ, with τ unknown at this pointdo
(let y = Cons"a" x in log (show y)) -- Here we find that τ = String, so x :: List String
(let z = Construe x in log (show z)) -- Boolean /= String, so why no error is repported here ?
The error is correctly emitted when the arity of the List type is modified :
moduleMainwhereimportPrelude (classShow, Unit, discard, show, (<>))
importEffect (Effect)
importEffect.Console (log)
dataListab=Nila | Consb (Listab)
instance (Showa, Showb) =>Show (Listab) where
show (Nil x) = "(Nil " <> show x <> ")"
show (Cons hd tl) = "(Cons " <> show hd <> "" <> show tl <> ")"main::EffectUnit
main = let x = Nil1in-- x :: List Int τ, with τ unknown at this pointdo
(let y = Cons"a" x in log (show y)) -- Here we find that τ = String, so x :: List Int String
(let z = Construe x in log (show z)) -- Boolean /= String, so we GET an error repported here.
To Reproduce
To reproduce this problem, simply copy-paste each of the examples into the Main.purs file generated by spago init, then call spago build.
You can also use try.purescript.org :
I expected the compiler to behave consistently, regardless of the arity of the List type introduced. That is, an error would be returned at the point explained in the comments in the first code snippet.
Probably #3874 I don't know if it's generalization so much as Nil is an identifier with a known type so it just accepts it's type as-is (lazy instantiation).
Description
Hi ! I've been playing around with PureScript's typing system and I've come across an example where the compiler's behaviour doesn't seem consistent.
In my experiments and as mentioned in ticket #4498, PureScript does not generalise let expressions. So why is the following code accepted by the compiler? The reasons why I think this code should not be accepted are in the comments to the following code.
The error is correctly emitted when the arity of the
List
type is modified :To Reproduce
To reproduce this problem, simply copy-paste each of the examples into the
Main.purs
file generated byspago init
, then callspago build
.You can also use try.purescript.org :
Expected behavior
I expected the compiler to behave consistently, regardless of the arity of the
List
type introduced. That is, an error would be returned at the point explained in the comments in the first code snippet.PureScript version
v0.15.13 (with try.purescript.org) and v0.15.12 (on my computer).
The text was updated successfully, but these errors were encountered: