Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I define a type synonym inside the "let" block?

I want to get something like this. It’s possible?

something :: String
something = 
  let
    type FirstName = String
    type LastName = String
    
    fullName :: FirstName -> LastName -> String
    fullName = a ++ " " ++ b
  in
    fullName "Haskell" "Curry"

I’ve been trying to find language extensions that do this, but to no avail.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Direct answer is no, type definitions are possible only on module level.

Something similar is possible:

let
  fullName ::
    (firstName ~ String, lastName ~ String) =>
    firstName -> lastName -> String
  fullName = a ++ " " ++ b
in
  _
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading