Advertisement
Guest User

Implicit parameters and classes

a guest
Jan 31st, 2025
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# language ImplicitParams #-}
  2. module Gato where
  3.  
  4. import Data.Text
  5.  
  6. -- Implicit parameter
  7. type WithConnectionString = ?connectionString :: Text
  8.  
  9. class DumbShowConnectionString a where
  10.   dumb :: a -> Text
  11.  
  12. instance DumbShowConnectionString Text where
  13.   dumb = id @Text
  14.  
  15. instance (?connectionString :: Text) => DumbShowConnectionString () where
  16.   dumb () = ?connectionString
  17.  
  18. -- Fails
  19. instance WithConnectionString => DumbShowConnectionString () where
  20.   dumb () = ?connectionString
  21.  
  22. {-
  23. [1 of 1] Compiling Gato             ( gato.hs, interpreted )
  24.  
  25. gato.hs:16:10: error: [GHC-75863]
  26.     • Illegal implicit parameter ‘?connectionString::Text’
  27.     • In the instance declaration for ‘DumbShowConnectionString ()’
  28.    |
  29. 16 | instance WithConnectionString => DumbShowConnectionString () where
  30.    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  31. Failed, no modules loaded.
  32. ghci> :r
  33. [1 of 1] Compiling Gato             ( gato.hs, interpreted )
  34.  
  35. gato.hs:16:10: error: [GHC-75863]
  36.     • Illegal implicit parameter ‘?connectionString::Text’
  37.     • In the instance declaration for ‘DumbShowConnectionString ()’
  38.    |
  39. 16 | instance (?connectionString :: Text) => DumbShowConnectionString () where
  40.    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  41.  
  42. gato.hs:20:10: error: [GHC-75863]
  43.     • Illegal implicit parameter ‘?connectionString::Text’
  44.     • In the instance declaration for ‘DumbShowConnectionString ()’
  45.    |
  46. 20 | instance WithConnectionString => DumbShowConnectionString () where
  47.    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  48. Failed, no modules loaded.
  49. ghci>
  50. -}
Tags: Haskell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement