Skip to content

Instantly share code, notes, and snippets.

@parsonsmatt parsonsmatt/drf.hs
Last active Jul 30, 2019

Embed
What would you like to do?
I'm upset
{-# language DuplicateRecordFields, TypeApplications #-}
module DuplicateRecordFields where
data User = User { name :: String }
data Dog = Dog { name :: String }
-- Works
nameAlias :: User -> String
nameAlias = name
-- Error:
-- drf.hs:9:15-18: error:
-- Ambiguous occurrence ‘name’
-- It could refer to either the field ‘name’, defined at drf.hs:6:18
-- or the field ‘name’, defined at drf.hs:5:20
-- |
-- 9 | nameAlias2 u = name u
-- | ^^^^
-- nameAlias2 :: User -> String
-- nameAlias2 u = name u
r :: (r -> a) -> r -> a
r f = f
-- works
nameAlias3 :: User -> String
nameAlias3 = r @User name
-- what in the hell
nameAlias4 :: User -> String
nameAlias4 u = r @User name u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.