-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chapter 12 Exercise InsertRight #114
Comments
|
Here's the link: https://privatebin.net/?2b64c18c8da919bc#BPts1wpxjXVxaLyzqM9RdhP5Zwtp6E2AqhkxcainToFg I haven't modified the signatures. My implementation for |
Hi John,
This kind of thing can happen sometimes as an odd consequence of local
inference.
Suppose you have two "public" functions
foo :: Nat -> Nat
foo x = incr x
bar :: Int -> Int
bar x = incr x
both of which use a "private" helper function
incr :: Int -> Int
incr x = 2 * x
If you OMIT a signature for `incr`, then LH infers that INCR has the type
incr :: Nat -> Nat
as it is only called by `foo` with `Nat` inputs.
However, if you _add_ the function `bar` into the mix, then LH infers a
weaker type for incr,
incr :: Int -> Int
which is too weak to prove the type of `foo`, thus triggering an error in
`foo`.
As an example see this
http://goto.ucsd.edu:8090/index.html#?demo=permalink%2F1627321397_37616.hs
So: in your case, check if there is some common helper function who lacks a
type signature?
|
Or can you send me the full code (in addition to insR) you’re running so I
can see if it’s this or something else ?
Thanks!
…On Mon, Jul 26, 2021 at 10:47 AM Ranjit Jhala ***@***.***> wrote:
Hi John,
This kind of thing can happen sometimes as an odd consequence of local
inference.
Suppose you have two "public" functions
foo :: Nat -> Nat
foo x = incr x
bar :: Int -> Int
bar x = incr x
both of which use a "private" helper function
incr :: Int -> Int
incr x = 2 * x
If you OMIT a signature for `incr`, then LH infers that INCR has the type
incr :: Nat -> Nat
as it is only called by `foo` with `Nat` inputs.
However, if you _add_ the function `bar` into the mix, then LH infers a
weaker type for incr,
incr :: Int -> Int
which is too weak to prove the type of `foo`, thus triggering an error in
`foo`.
As an example see this
http://goto.ucsd.edu:8090/index.html#?demo=permalink%2F1627321397_37616.hs
So: in your case, check if there is some common helper function who lacks
a type signature?
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get errors when I try to define
insR
symmetrically to howinsL
has been defined above. However, these errors are aboutinsL
rather thaninsR
. How can it be? These are the errors I get:How can it be that modifying one function breaks another independent function?
The text was updated successfully, but these errors were encountered: