4

There is a Haskell program called inline-C which allows C code snippets to placed inline Haskell code, as follows:

main :: IO ()
main = do
  x <- [C.block| int {
      // Read and sum 5 integers
      int i, sum = 0, tmp;
      for (i = 0; i < 5; i++) {
        scanf("%d", &tmp);
        sum += tmp;
      }
      return sum;
    } |]
  print x

As you can see, there is a C code snippet above in between the [C.block| and |].

Is there a way to make it so that portions of code in between these are highlighted as C code?

3

You can include syntax files with syn include. Putting this in ~/.vim/after/syntax/haskell.vim seems to work fairly well:

" C syntax file won't load if this is set
unlet b:current_syntax

" Load C syntax
syn include @C syntax/c.vim

" Define a syntax region which can contain C syntax
syn region haskellC keepend
    \ start=/\v(\[C\.block\|)@<= \w+ \{/
    \ end=/} \|]/
    \ contains=@C

" Re-set the current syntax
let b:current_syntax = 'haskell'

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.