Opened 3 years ago

Last modified 3 months ago

#5296 new feature request

Add explicit type applications

Reported by: dsf Owned by:
Priority: low Milestone: 7.6.2
Component: Compiler (Type checker) Version: 7.0.3
Keywords: Cc: dsf@…, hackage.haskell.org@…, sweirich@…, mail@…, steven.keuchel@…, hamidhasan14@…, jan.stolarek@…
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: GHC rejects valid program Difficulty: Project (more than a week)
Test Case: Blocked By: #1897
Blocking: Related Tickets:

Description

This example is derived from code in my application. It works, but I can't add a signature to it. In other places it is preventing some code from compiling at all.

{-# LANGUAGE KindSignatures, MultiParamTypeClasses, RankNTypes #-}
{-# OPTIONS -Wall #-}
module Test where

class C t1 t2 m where method :: Int -> m t2

f :: forall t1 t2 (m :: * -> *). C t1 t2 m => Int -> m t2
f x = method x

Change History (14)

comment:1 in reply to: ↑ description Changed 3 years ago by dsf

Replying to dsf:

To be clear, to get the module to load remove the signature from f. In my application I might be able to get things working by removing signatures, but it leads to a cascade of signature removal that is not really acceptable.

comment:2 Changed 3 years ago by dsf

  • Blocked By 1897 added
  • Cc dsf@… added

comment:3 Changed 3 years ago by liyang

  • Cc hackage.haskell.org@… added

comment:4 Changed 3 years ago by igloo

  • Milestone set to 7.4.1

comment:5 Changed 3 years ago by simonpj

The problem here is related to #1897, as you point out, but is even clearer because it doesn't even involve type families. The trouble is this. method has type

method :: C t1 t2 m => Int -> m t2

Notice that t1 does not appear in method's type. Now GHC is faced with

From   given  (C t1 t2 m)  
deduce wanted (C t3 t2 m)

Notice the t3. The call of method means that the second and third args of C must be t2, m; but the first can be anything. So type inference is supposed to guess what type it should use for t3. Here there is a unique choice, but in general it is hard to solve problems where there is are positive clues, only that there is just one magic solution.

If we could supply the type arguments to the call to method, we could say this:

f :: forall t1 t2 (m :: * -> *). C t1 t2 m => Int -> m t2
f x = method @t1 @t2 @m x

Here I put the type args with a leading "@" (the notation I'm currently considering for type args). Now we'd be fine.

In short, the only Decent Solution here seems to me to be explicit type arguments. Unless anyone else has better ideas.

comment:6 Changed 3 years ago by simonpj

  • Summary changed from Compile succeeds without signature, but fails with the signature suggested by GHC to Add explicit type applications
  • Type changed from bug to feature request

comment:7 Changed 3 years ago by simonpj

See also #4466

comment:8 Changed 2 years ago by igloo

  • Milestone changed from 7.4.1 to 7.6.1
  • Priority changed from normal to low

comment:9 Changed 20 months ago by igloo

  • Milestone changed from 7.6.1 to 7.6.2

comment:10 Changed 12 months ago by sweirich

  • Cc sweirich@… added

comment:11 Changed 12 months ago by kosmikus

  • Cc mail@… added

comment:12 Changed 10 months ago by skeuchel

  • Cc steven.keuchel@… added

comment:13 Changed 9 months ago by Hamidhasan

  • Cc hamidhasan14@… added
  • Difficulty set to Project (more than a week)

comment:14 Changed 3 months ago by jstolarek

  • Cc jan.stolarek@… added
Note: See TracTickets for help on using tickets.