[GHC] #13783: 更合理的instance Monad []

#13783: 更合理的instance Monad [] -------------------------------------+------------------------------------- Reporter: zaoqi | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Core | Version: 8.0.1 Libraries | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect result Unknown/Multiple | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- 使 {{{#!hs join $ map (\y->map (\x->(x,y)) [1..]) [1..] }}} 的结果更合理: https://github.com/zaoqi/zaoqilc/blob/master/featuring/MonadList.hs -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13783 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13783: 更合理的instance Monad [] -------------------------------------+------------------------------------- Reporter: zaoqi | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: Component: Core Libraries | Version: 8.0.1 Resolution: wontfix | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * status: new => closed * resolution: => wontfix Comment: In English, the reporter is suggesting that the Monad instance of list be rewritten so that it generates a fairer distribution of tuples (in the example above, all tuples generated are of the form `(x, 1)`). The fairness of these types of nondeterminism monads is indeed something that has been investigated in the past (e.g., http://okmij.org/ftp/Computation/LogicT.pdf). Unfortunately, the semantics of the List monad as defined in Haskell are fairly set in stone at this point, and can't be changed without massively breaking existing code. The best course of action is probably to define your own monad with the necessary fairness (do consider using CPS; it's a lot more efficient!) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13783#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

In English, the reporter is suggesting that the Monad instance of list be rewritten so that it generates a fairer distribution of tuples (in the example above, all tuples generated are of the form `(x, 1)`). The fairness of these types of nondeterminism monads is indeed something that has been investigated in the past (e.g., http://okmij.org/ftp/Computation/LogicT.pdf). Unfortunately, the semantics of the List monad as defined in Haskell are fairly set in stone at this
#13783: 更合理的instance Monad [] -------------------------------------+------------------------------------- Reporter: zaoqi | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: Component: Core Libraries | Version: 8.0.1 Resolution: wontfix | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by zaoqi): Replying to [comment:1 ezyang]: point, and can't be changed without massively breaking existing code. The best course of action is probably to define your own monad with the necessary fairness (do consider using CPS; it's a lot more efficient!) What's CPS? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13783#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13783: 更合理的instance Monad [] -------------------------------------+------------------------------------- Reporter: zaoqi | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: Component: Core Libraries | Version: 8.0.1 Resolution: wontfix | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): zaoqi, you should look at [https://hackage.haskell.org/package/logict LogicT] for an example of the continuation-passing style (CPS) approach. But please note that that approach also has severe efficiency problems in some cases. For a solution that's never very fast but also never terribly slow, read the paper called "Reflection Without Remorse". -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13783#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC