Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,273
    • Issues 4,273
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 413
    • Merge Requests 413
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #5858

Closed
Open
Opened Feb 08, 2012 by GregWeber@trac-GregWeber

type inference of an OverloadedString for a class instance with type parameters

We have some code in Yesod:

class RedirectUrl master a where
    -- | Converts the value to the URL and a list of query-string parameters.
    toTextUrl :: a -> GHandler sub master Text

instance t ~ Text => RedirectUrl master (Route master, [(t, t)]) where
    toTextUrl (u, ps) = do
        r <- getUrlRenderParams
        return $ r u ps

When I use it in my application, I am required to give an annotation to the overloaded strings. If I don't:

redirect $ (SearchR, [("foo", "bar")])

I end up with this error message:

    No instance for (RedirectUrl Search (Route Search, [(t0, t1)]))
      arising from a use of `redirect'
    Possible fix:
      add an instance declaration for
      (RedirectUrl Search (Route Search, [(t0, t1)]))
    In the expression: redirect
    In the expression: redirect $ (SearchR, [("foo", "bar")])
    In an equation for `getFoodsr23R':
        getFoodsr23R foodId = redirect $ (SearchR, [("foo", "bar")])

I would be ok with having to type annotate if instead of the compiler suggesting I declare an entire new instance the compiler instead suggested that I annotate my overloaded strings.

However, in trying to reproduce this program in a simpler setting, it seems to normally perform the OverloadedStrings inference without any issue. This works just fine:

{-# LANGUAGE OverloadedStrings, NoMonomorphismRestriction, FlexibleInstances, GADTs #-}
module InferOverloaded where
import Data.Text

class InferOverloaded a where
  infer :: a -> a

data Data = Data String

instance t ~ Text => InferOverloaded (Data, [(t,t)]) where
  infer = id

foo = infer (Data "data", [("overloaded", "strings")])
Edited Mar 09, 2019 by Simon Peyton Jones
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#5858