F# Inline Function Specialization
Posted
by
Ben
on Stack Overflow
See other posts from Stack Overflow
or by Ben
Published on 2010-12-21T06:47:55Z
Indexed on
2010/12/21
6:54 UTC
Read the original article
Hit count: 298
Hi,
My current project involves lexing and parsing script code, and as such I'm using fslex and fsyacc. Fslex LexBuffers can come in either LexBuffer<char>
and LexBuffer<byte>
varieties, and I'd like to have the option to use both.
In order to user both, I need a lexeme function of type ^buf -> string. Thus far, my attempts at specialization have looked like:
let inline lexeme (lexbuf: ^buf) : ^buf -> string where ^buf : (member Lexeme: char array) =
new System.String(lexbuf.Lexeme)
let inline lexeme (lexbuf: ^buf) : ^buf -> string where ^buf : (member Lexeme: byte array) =
System.Text.Encoding.UTF8.GetString(lexbuf.Lexeme)
I'm getting a type error stating that the function body should be of type ^buf -> string
, but the inferred type is just string
. Clearly, I'm doing something (majorly?) wrong.
Is what I'm attempting even possible in F#? If so, can someone point me to the proper path?
Thanks!
© Stack Overflow or respective owner