컴퓨터컴퓨터
컴퓨터
/
프로그래밍 언어프로그래밍 언어
프로그래밍 언어
/
HaskellHaskell
Haskell
/코드 조각/
레코드의 이름 충돌

레코드의 이름 충돌

 
  • 다음과 같은 레코드가 있다.
Person = Person { firstName :: String , lastName :: String , age :: Int } deriving (Eq, Show, Read) data Human = Human { firstName :: String , lastName :: String , age :: Int } deriving (eq, Show, Read)
  • 필드 레코드 처럼 표기하는 하스켈에서는 당연히 위처럼 하면 에러가 생긴다.
 

해결 방법

  1. Control.Lens 를 쓰자
  1. 아예 모듈을 나누자.
 
Name conflicts in Haskell records
Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience. To learn more, see our tips on writing great answers.
Name conflicts in Haskell recordsName conflicts in Haskell records
https://stackoverflow.com/questions/17478599/name-conflicts-in-haskell-records
Name conflicts in Haskell recordsName conflicts in Haskell records
 
Working around Haskell's namespace problem for records
Defining records in Haskell causes accessor functions for the record's fields to be defined. There is no seperate namespace for these accessor functions. Be able to use records in Haskell, which share field names. use lenses for accessing these fields use bindings in code with the same name as the record's fields avoiding any namespace clashes avoid overly verbose code and boilerplate as much as possible.
Working around Haskell's namespace problem for recordsWorking around Haskell's namespace problem for records
https://gist.github.com/mtesseract/1b69087b0aeeb6ddd7023ff05f7b7e68
Working around Haskell's namespace problem for recordsWorking around Haskell's namespace problem for records