0

I am a data scientist familiar with languages such as R and python. I have been trying to learn haskell for two months.

There is a module people employ to deal with frames in haskell similarly to common packages in those other languages (tidyverse in R and pandas in python).

The problem is: the common function for extracting data type for a csv is simply returning a message error:

tableTypes "base" "base.csv"

<interactive>:2:1: error:
    • No instance for (Show Language.Haskell.TH.Lib.DecsQ)
        arising from a use of ‘print’
    • In a stmt of an interactive GHCi command: print it

I cannot understand what this message means and I could not find any answer on Google. Could someone help me solve it?

Link to the module: http://hackage.haskell.org/package/Frames

  • 1
    I really wish template Haskell had never been modified to accept bare expressions at the top level. Is saving 3 tokens worth all the confusion it causes? – Carl Jul 31 '18 at 04:25
  • 2
    I cannot find the`tableTypes` from hoogle. Please provide link to the module – max630 Jul 31 '18 at 04:26
  • @max630 https://hackage.haskell.org/package/Frames-0.4.0/docs/Frames-CSV.html#v:tableType – Carl Jul 31 '18 at 04:29
  • 1
    maybe you need this: https://stackoverflow.com/a/25392121/2303202 – max630 Jul 31 '18 at 04:45

1 Answers1

1

You've stumbled into a case that's involves some advanced features of Haskell. The problem is that tableTypes "base" "base.csv" is a template haskell splice. For some reason, a few years back ghc was modified to allow bare expressions at the top level as splices, instead of requiring the standard splice syntax of $(expression generating code to splice).

But the bare expression syntax is incompatible with ghci. If you enter a bare expression in ghci, it tries to evaluate and print it (with some special rules for expressions that result in IO values).

When ghci evaluates tableTypes "base" "base.csv" it gets a result back that's not an instance of Show, because the template haskell Q environment is not printable. It contains a bunch of functions.

You have a few options here, depending on what you actually are trying to do. You could use runQ in ghci to dump the AST generated by the splice. That's probably not what you want. That's more likely to be a tool that's useful when you're developing a splice than for testing a library that uses them.

You could enable the TemplateHaskell extension within ghci and actually have it perform the splice interactively, but that's somewhat fiddly to get to work and you don't end up seeing much anyway.

I think the most practical solution is to move your code into a file. You can load said file from ghci if you desire - the important part is that in the context of a file, there's no longer any syntactic ambiguity - that's definitely a splice to evaluate while compiling, not an expression to evaluate interactively.

Carl
  • 26,500
  • 4
  • 65
  • 86
  • Your answer was really good, but even trying to compile the file, using ghc, it didn't work. It shows the same problem. – Guilherme Jardim Duarte Jul 31 '18 at 14:45
  • You're going to have to update the question. There's no way that can get the *same* error in a file. There are still lots of ways to get *some* error, but the fix depends on the error. – Carl Jul 31 '18 at 14:51