3 ms·
Oh I misunderstood `type T Thing` to be an alias and not a haskell-style newtype. $ ghci GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help P
by hiptobecubic 4y ago
Oh I misunderstood `type T Thing` to be an alias and not a haskell-style newtype.
$ ghci
GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help
Prelude> class HasField a where { field1 :: a -> Int }
Prelude> data Foo = Foo
Prelude> instance HasField Foo where { field1 f = 2 }
Prelude> field1 Foo
2
Prelude> newtype Bar = Bar Foo
Prelude> :t Bar
Bar :: Foo -> Bar
Prelude> field1 (Bar Foo)
<interactive>:7:1: error:
• No instance for (HasField Bar) arising from a use of
‘field1’
• In the expression: field1 (Bar Foo)
In an equation for ‘it’: it = field1 (Bar Foo)
Prelude> type Baz = Foo
Prelude> field1 (Foo :: Baz)
2
- morelisp 4y agoThere's an unfortunately-close syntax that does define type aliases in Go, type T = Thing