Search code examples
haskellindentation

How to indent OSC config correctly


I am trying to find the right indentation for an OSC configuration in a haskell file. When I write the following in two lines it

unityTarget :: OSCTarget
unityTarget = OSCTarget {oName = "unityTarget", oAddress = "10.0.0.3", oPort = 7000, oPath = "/tidal", oShape = Nothing, oLatency = 0.02, oPreamble = [], oTimestamp = MessageStamp }

works but if I use the following indentation, it doesn´t and gives me a parse error: possibly wrong indentation or missmatched brackets. I tried variations but none of them works. Any help appreciated.

unityTarget :: OSCTarget
unityTarget = OSCTarget {oName = "unityTarget",
                         oAddress = "10.0.0.3",
                         oPort = 7000,
                         oPath = "/tidal",
                         oShape = Nothing,
                         oLatency = 0.02,
                         oPreamble = [],
                         oTimestamp = MessageStamp
                        }

Solution

  • I suspect whatever tool you are using is sending its output to ghci, rather than using ghc directly for some reason. ghci is designed to be interactive, and so by default, it accepts a line at a time and processes it immediately. This causes two problems: your type signature will be handled on its own, and ghci will complain that there's no accompanying binding; and the unityTarget = OSCTarget {oName = "unityTarget", line will be handled on its own, and ghci will complain that the { is not closed (but with the unhelpful "parse error" message you are probably seeing).

    The simplest fix is to enclose any multiline things with :{ and :}, which are ghci's markers for beginning and ending a multiline command, as seen elsewhere in the example file you posted, so:

    :{
    unityTarget :: OSCTarget
    unityTarget = OSCTarget {oName = "unityTarget",
                             oAddress = "10.0.0.3",
                             oPort = 7000,
                             oPath = "/tidal",
                             oShape = Nothing,
                             oLatency = 0.02,
                             oPreamble = [],
                             oTimestamp = MessageStamp
                            }
    :}