Table of Contents
1. Human-centric
Using a value before defining it
Haskell does not require that a value or function be declared or defined in a source file before it’s used. It’s perfectly normal for a definition to come after the first place it’s used. The Haskell compiler doesn’t care about ordering at this level. This grants us the flexibility to structure our code in the manner that makes most logical sense to us, rather than follow an order that makes the compiler writer’s life easiest. Haskell module writers often use this flexibility to put “more impor- tant” code earlier in a source file, relegating “plumbing” to later. This is exactly how we are presenting the globToRegex function and its helpers here.
上述观点强调了Haskell语言的灵活性,即在代码中可以先使用某个值或函数,再进行定义。这种特性使得程序员能够根据逻辑结构来组织代码,而不是仅仅遵循编译器的要求。模块作者常常将“重要”代码放在前面,“辅助”工具放在后面,从而改善代码的可读性和逻辑性。