Featured post
F# Inline Function Specialization -
my current project involves lexing , parsing script code, , such i'm using fslex , fsyacc. fslex lexbuffers can come in either lexbuffer<char>
, lexbuffer<byte>
varieties, , i'd have option use both.
in order user both, need lexeme function of type ^buf -> string. far, attempts @ specialization have looked like:
let inline lexeme (lexbuf: ^buf) : ^buf -> string ^buf : (member lexeme: char array) = new system.string(lexbuf.lexeme) let inline lexeme (lexbuf: ^buf) : ^buf -> string ^buf : (member lexeme: byte array) = system.text.encoding.utf8.getstring(lexbuf.lexeme)
i'm getting type error stating function body should of type ^buf -> string
, inferred type string
. clearly, i'm doing (majorly?) wrong.
is i'm attempting possible in f#? if so, can point me proper path?
thanks!
functions , members marked inline
cannot overloaded, original strategy won't work. need write different code both of declarations, need use overloading (if want write without boxing , dynamic type tests).
if you're using standard f# tools, type you'll buffer lexbuffer<'t>
, want have 2 overloads based on type argument. in case, don't need static member constraints @ , can write just:
type utils = static member lexeme(buf:lexbuffer<char>) = new system.string(buf.lexeme) static member lexeme(buf:lexbuffer<byte>) = system.text.encoding.utf8.getstring(buf.lexeme)
- Get link
- X
- Other Apps
Comments
Post a Comment