ndmitchell / debug

Haskell library for debugging
BSD 3-Clause "New" or "Revised" License
122 stars 7 forks source link

Illegal variable name when splicing a TH declaration #64

Open gfarrell opened 4 years ago

gfarrell commented 4 years ago

I'm trying to use debug to instrument a function. I have followed the instructions, so the top of my source file looks like this:

{-# LANGUAGE TemplateHaskell, ViewPatterns, PartialTypeSignatures #-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}

module Day2 (
    -- ...
) where

import Util
import Debug

I'm instrumenting the function as follows:

debug [d|
    _seek_from :: (Integer, Integer) -> Integer -> [Integer] -> Maybe (Integer, Integer)
    _seek_from (a, b) t [] = Nothing
    _seek_from (a, b) t mem
      | a > bound && b > bound = Nothing
      | a < 0 || b < 0 = Nothing
      | a > bound && b <= bound = _seek_from (0, b + 1) t mem
      | otherwise =
            let r = test_inputs (a, b) mem in
            if r == t then Just (a, b) else _seek_from (a + 1, b) t mem
      where bound = let x = toInteger . ((-) 1) . length $ mem in if x > 99 then 99 else x
      |]

When I build (stack build) I get the following error:

Illegal variable name: ‘’Illegal variable name: ‘’
    When splicing a TH declaration

It specifically has a problem on the debug [d| line.

ndmitchell commented 4 years ago

The use of _ as function names looks odd. Perhaps try removing that?

The debug library is not massively supported at the moment, so you may be on your own if it doesn't work easily I'm afraid.