Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,862
    • Issues 4,862
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 455
    • Merge requests 455
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #12360
Closed
Open
Created Jul 02, 2016 by MichaelBurge@trac-MichaelBurge

Extend support for binding implicit parameters

Implicit parameters can only be bound using simple let and where declarations. In this example, one would expect ?t to be bound to the result of getCurrentTime, however the program is rejected with a syntax error:

{-# LANGUAGE ImplicitParams #-}

import Data.Time.Clock

printTime :: (?t :: UTCTime) => IO ()
printTime = putStrLn $ show ?t

main = do
  ?t <- getCurrentTime
  printTime

Instead, one must first bind to a regular variable and then bind the implicit parameter to it:

{-# LANGUAGE ImplicitParams #-}

import Data.Time.Clock

printTime :: (?t :: UTCTime) => IO ()
printTime = putStrLn $ show ?t

main = do
  t <- getCurrentTime
  let ?t = t
  printTime

In general, it seems like any pattern binding involving implicit parameters could be rewritten as a pattern binding to ordinary variables, followed by a binding of the implicit parameters to the ordinary variables. So you could bind implicit parameters buried in variables, tuples, record fields, etc.:

Sugared:

{-# LANGUAGE ImplicitParams #-}

data Example = Example { a :: Int, b :: Int, c :: Int }

f :: (?a :: Int, ?b :: Int, ?c :: Int) => Int
f = ?a + ?b + ?c

main = do
  let x = Example 1 2 3
  let (Example { a = ?a, b = ?b, c = ?c }) = x
  putStrLn $ show f

Desugared:

{-# LANGUAGE ImplicitParams #-}

data Example = Example { a :: Int, b :: Int, c :: Int }

f :: (?a :: Int, ?b :: Int, ?c :: Int) => Int
f = ?a + ?b + ?c

main = do
  let x = Example 1 2 3
  let (Example { a = a, b = b, c = c }) = x
  let ?a = a
      ?b = b
      ?c = c
  putStrLn $ show f
Edited Mar 10, 2019 by MichaelBurge
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking