2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JSのように簡潔にレコードをつくる方法

Last updated at Posted at 2023-01-26

追記 2023.07.25

RIOのREADMEに、詳細は追ってませんが、次のような注記あり。

RecordWildCards is really up for debate. It's widely used, but rightfully considered by many to be dangerous. Open question about what we do with it.


(以下原文)

RecordWildCards 拡張を導入すると次のような簡潔な方法でデータを生成できる。

#!/usr/bin/env stack
-- stack --resolver lts-20.7 script

{-# LANGUAGE RecordWildCards #-}

data MyData = MyData
  { foo :: !String
  , bar :: !String
  } deriving (Show)

main :: IO ()
main = do
  let foo = "Foo"
  let bar = "Bar"
  let myData = MyData {..}
  print myData -- Output: MyData {foo = "Foo", bar = "Bar"}

参考文献

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?