Use GeneralizedNewtypeDeriving
and derive the IsString
instance for Firstname
and Lastname
. A sample code for your example follows
{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving #-}
import Data.String
newtype Firstname = Firstname String deriving (Eq, Show, IsString)
newtype Lastname = Lastname String deriving (Eq, Show, IsString)
data Person = Person { firstname :: Firstname
, lastname :: Lastname
, age :: Int
}
foo = Person "hello" "world" 10
You can use TH to write a similar function which you want but it is not worth the effort while keeping those functions in a separate module and then importing them here.