Opened 5 years ago

Closed 5 years ago

## #8931 closed bug (fixed)

# The type defaulting in GHCi with Typeable

Reported by: | skata | Owned by: | |
---|---|---|---|

Priority: | normal | Milestone: | 7.8.1 |

Component: | Compiler (Type checker) | Version: | 7.8.1-rc2 |

Keywords: | type defaulting, Typeable | Cc: | |

Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |

Type of failure: | GHC rejects valid program | Test Case: | ghci/scripts/T8931 |

Blocked By: | Blocking: | ||

Related Tickets: | Differential Rev(s): | ||

Wiki Page: |

### Description

The type defaulting in GHCi works in less cases with GHC 7.8.1-rc2 than with older versions, though there is no change in the related part of the documentation (i.e., "2.4.7 Type defaulting in GHCi").

skata@kata58:~$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.8.0.20140228 skata@kata58:~$ ghci GHCi, version 7.8.0.20140228: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> :m +Data.Typeable Prelude Data.Typeable> let {f :: Read a => (a->Bool) -> Char; f = undefined} Prelude Data.Typeable> f (\x -> (x == 3)) *** Exception: Prelude.undefined <== This is the expected result. Prelude Data.Typeable> let {f :: Typeable a => (a->Bool) -> Char; f = undefined} Prelude Data.Typeable> f (\x -> (x == 3)) <== Type defaulting does not work in this case. <interactive>:6:1: No instance for (Typeable a0) arising from a use of ‘f’ The type variable ‘a0’ is ambiguous Note: there are several potential instances: instance [overlap ok] Typeable () -- Defined in ‘Data.Typeable.Internal’ instance [overlap ok] Typeable Bool -- Defined in ‘Data.Typeable.Internal’ instance [overlap ok] Typeable Char -- Defined in ‘Data.Typeable.Internal’ ...plus 14 others In the expression: f (\ x -> (x == 3)) In an equation for ‘it’: it = f (\ x -> (x == 3)) <interactive>:6:13: No instance for (Eq a0) arising from a use of ‘==’ The type variable ‘a0’ is ambiguous Relevant bindings include x :: a0 (bound at <interactive>:6:5) Note: there are several potential instances: instance Eq a => Eq (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ instance Eq Integer -- Defined in ‘integer-gmp:GHC.Integer.Type’ instance Eq () -- Defined in ‘GHC.Classes’ ...plus 33 others In the expression: (x == 3) In the first argument of ‘f’, namely ‘(\ x -> (x == 3))’ In the expression: f (\ x -> (x == 3)) <interactive>:6:16: No instance for (Num a0) arising from the literal ‘3’ The type variable ‘a0’ is ambiguous Relevant bindings include x :: a0 (bound at <interactive>:6:5) Note: there are several potential instances: instance Num Double -- Defined in ‘GHC.Float’ instance Num Float -- Defined in ‘GHC.Float’ instance Integral a => Num (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ ...plus 7 others In the second argument of ‘(==)’, namely ‘3’ In the expression: (x == 3) In the first argument of ‘f’, namely ‘(\ x -> (x == 3))’

On the other hand,

skata@kata58:~$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.4.1 skata@kata58:~$ ghci GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> :m +Data.Typeable Prelude Data.Typeable> let {f :: Read a => (a->Bool) -> Char; f = undefined} Prelude Data.Typeable> f (\x -> (x == 3)) *** Exception: Prelude.undefined Prelude Data.Typeable> let {f :: Typeable a => (a->Bool) -> Char; f = undefined} Prelude Data.Typeable> f (\x -> (x == 3)) *** Exception: Prelude.undefined

I think the old behavior is compliant with the documentation.

### Change History (4)

### comment:1 Changed 5 years ago by

### comment:3 Changed 5 years ago by

Status: | new → merge |
---|---|

Test Case: | → ghci/scripts/T8931 |

Thanks for pointing this out.

Pls merge if convenient.

Simon

### comment:4 Changed 5 years ago by

Milestone: | → 7.8.1 |
---|---|

Resolution: | → fixed |

Status: | merge → closed |

Merged, thanks!

**Note:**See TracTickets for help on using tickets.

In 791f4fa24dd6929ab2e55c9f8b870d8078337427/ghc: