i attempting create function in haskell returning resp
type illustrated below in strange mix between bnf , haskell types.
elem ::= string | (string, string, resp) resp ::= [elem]
my question (a) how define type in haskell, , (b) if there way of doing without being forced use custom constructors, e.g., node
, rather using tuples , arrays.
part 1:
data elem = el string | node string string resp type resp = [elem]
part 2: well... kinda. unsatisfying answer is: shouldn't want because doing less type safe. more direct answer elem
needs it's own constructor resp
defined type synonym above. however, recommend
newtype resp = resp { getelems :: [elem] }
so can't mix random list of elem
s resp
. gives function getelems
don't have pattern matching on single constructor. newtype
let's haskell know should rid of overhead of constructor during runtime there's no indirection nice.
Comments
Post a Comment