haskell - Compile-time check if a name is defined -


is possible check if function defined, , use just value of maybe type if is? , use nothing if it's not defined, of course.

i'm writing wrapper around atom use ti msp430 line. part of i'm doing making function compiles code in right format msp430 controllers - example, compiling atom use in timer interrupt requires function definition so:

#pragma vector=timera0_vector __interrupt void timeraisr(void) {     ... } 

at moment, have object holds references function user use each different isr. looks bit this:

mspprogram = msp430compilation {     setupfn = nothing,     setupfnname = "setup",     loopfn = nothing,     loopfnname = "loop",     timeraisr = nothing,     timeraisrname = "timeraisr", 

and on. configurable - can choose name of function output in c code, , atom compile function. i've decided i'd take more of convention-over-configuration approach , assume sensible function names. instead of passing 1 of these configuration objects, want compilation code check definitions of sensibly-named functions.

for example, if user defines atom called timeraisr, code should compile atom c function named same, appropriate #pragma matter service timer interrupt.

so need sort of meta-haskell, checking if user has defined function , using in library code. imagine might involve template haskell, i'm off research it.

edit:

i've realised original solution simplistic once tried fit actual code. hadn't absorbed haskell's namespacing, didn't realise lookupvaluename not work on values defined in user code. here's situation i'm dealing with:

main.hs:

module main import library  = 1  main = librarymain 

library.hs:

{-# language templatehaskell #-}  module library import template  librarymain :: io () librarymain =     $(printsomethingifisdefined "a")     $(printsomethingifisdefined "b") 

template.hs:

{-# language templatehaskell #-}  module template import language.haskell.th  printsomethingifisdefined name = maybefn <- lookupvaluename name case maybefn of     fn -> [| putstrln "it's defined!" |]     nothing -> [| return () |] 

this prints nothing. if define a in library.hs, print out once, because a defined in scope.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -