Skip to content
Brandon Elam Barker edited this page Jun 2, 2020 · 5 revisions

Like any Haskell type, you can have a zero-cost embedding of MATLAB types into a newtype for better type-safety and clarity. This is particularly useful for MStruct, MStructArray, or even MAnyArray, since the API itself doesn't allow us to further refine these types statically. Here is an example.

However, for performance reasons, you may also want to know about Coercible when performing certain operations (like <$>) on containers of newtypes. So instead of doing unMyNewtype <$> [myNewTypes], you could instead just have (coerce [myNewTypes] :: [MStruct]), to get back a list of bare (unwrapped) values (in this case, a list of MStructs).

Clone this wiki locally