Importing a Custom Function File

Hi all!

I've started to amass a bunch of custom functions and it's getting to be a chore to keep track of them. Is there a way to create a file that imports all my functions on tidal's startup to get around this?

You can add them all to your own custom BootTidal.hs file. They’ll load automatically every time you launch Tidal (via your text editor).

Oh cool! I'll give it a try. Thx!

Can't you also load your functions using :l yourFileWithTidalFunctions.hs in your Tidal file?
As far as I understand you can use the GHCi commands from within Tidal.

1 Like

I just tried this method:

:l ~/test.hs

where the contents of test.hs is just

testList :: Int -> String
testList n = unwords $ replicate n "bd"

and it works to import the function:

Ok, modules loaded: Main.

But it seems to mess up tidal (in Atom), because after that, trying to send

d1 $ s "bd cp"

generates the error

    Not in scope: ‘d1’
    Perhaps you meant ‘dt’ (imported from Sound.Tidal.Context)

(but it worked fine before)

I found I could add a function definition in BootTidal.hs file like this:

let testList :: Int -> String
    testList n = unwords $ replicate n "bd"

I see the same when I try this using nvim, so I might be probably wrong - and I am sorry for that.

I am thinking, what if you defined your own function modules? But once you have it, I don't know exactly where you should import it. @yaxu do you have any suggestion / good practice?

You can use :script instead. For multi-line blocks of code you have to wrap in :{ and :} though. Have a look at BootTidal.hs for examples, which is itself loaded using :script
I'm sure there's a way of loading modules without losing current state but am not sure of the best way to do this off the top of my head