Skip to content

Instantly share code, notes, and snippets.

@theqp

theqp/Foo.hs Secret

Created January 14, 2021 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theqp/8f049861498df238f398b87c8e401fc4 to your computer and use it in GitHub Desktop.
Save theqp/8f049861498df238f398b87c8e401fc4 to your computer and use it in GitHub Desktop.
{-# LANGUAGE NamedFieldPuns #-}
module Foo where
newtype MyData = MyData {myField :: Integer}
f :: MyData -> Integer
f MyData {myField} = myField
-- I want to ensure that f is called only with a variable named myField
-- this does work but too verbose
-- something like "f {myField}" would be better
-- "f MyData {otherField}" shows a syntax error and that is the purpose
foo =
let myField = 1; otherField = 2
in f MyData {myField}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment