Skip to content

Instantly share code, notes, and snippets.

@axelerator
Last active October 31, 2021 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axelerator/2dc7df08ad658aa017e84f78ef77bab0 to your computer and use it in GitHub Desktop.
Save axelerator/2dc7df08ad658aa017e84f78ef77bab0 to your computer and use it in GitHub Desktop.
Confusing/Misleading Haskell error messages

Haskell has error messages that often add to the confusion rather than helping to remove it.

I collect some anecdotal examples here.

Missing extension

data EventResponse
  = Success
  | FailedParse String
  deriving (Generic)

Error:

    • Can't make a derived instance of ‘Generic EventResponse’:
        You need DeriveGeneric to derive an instance for this class
    • In the data declaration for ‘EventResponse’
   |
79 |   deriving (Generic)

meaning

You forgot to put {-# LANGUAGE DeriveGeneric #-} at the top

Strings

/Users/at/dev/tutor/backend/src/Clients.hs:106:25: error:
    • Couldn't match expected type ‘Data.ByteString.Builder.Internal.Builder’
                  with actual type ‘Data.ByteString.Internal.ByteString’
    • In the expression: C.toStrict $ encode frontendEvent
      In the ‘eventData’ field of a record
      In the expression:
        ServerEvent
          {eventName = Nothing, eventId = Nothing,
           eventData = [C.toStrict $ encode frontendEvent]}

Solution eventData = [ fromByteString $ C.toStrict $ encode frontendEvent ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment