Search code examples
haskellihp

How to qualify name of a field when using generated types


How do you qualify the name of a field within a function like this:

let sortedIssues :: [Issue] = sortOn updatedAt issues

I have an issues table with an updated_at column. However, I also have another table with an updated_at column so the compiler does not know which one I am referring to in the above function.

Trying to qualify the above as Issue.updatedAt does not work since there is no Issue module. The IHP-generated types are all within just one module as well, so importing Generated.Types does not help.


Solution

  • It's best to use dot notation here to avoid this problem:

    let sortedIssues :: [Issue] = sortOn (.updatedAt) issues
    

    This short form notation is a shorthand for this:

    let sortedIssues :: [Issue] = sortOn (\issue -> issue.updatedAt) issues