[Haskell-cafe] ParallelListComp strange behavior

Michael Jones mike at proclivis.com
Wed Jan 14 21:36:47 UTC 2015


I figured it out. Constant values work fine when not in the generator.

My main problem was a more subtle short list. The obvious ones were added when trying to test behavior, as they were originally just constant values in the constructor. When I removed them all, I found an offending generator that was not so obvious.

Thanks

On Jan 14, 2015, at 1:10 PM, Michael Jones <mike at proclivis.com> wrote:

> If one of the values in the constructor is a constant value, and not in the generator, is it excluded from the zip or is it also zipping that parameter too?
> 
> 
> On Jan 13, 2015, at 5:44 PM, Michael Sloan <mgsloan at gmail.com> wrote:
> 
>> In the real code, a number of the lists being zipped have only one
>> value, such as suPol, sdPol, fault_other, so the result will have at
>> most one value.  Like with zip, the length of the resulting list is
>> the length of the shortest list.   So, [(x,y) | x <- [1] | y <- [1..]]
>> == [(1,1)].  Maybe you want normal list comprehensions with "," rather
>> than "|"?
>> 
>> On Tue, Jan 13, 2015 at 3:04 PM, Michael Jones <mike at proclivis.com> wrote:
>>> I am trying to use ParallelListComp and have code that compiles but only produces one value, but I am not clear why.
>>> 
>>> The code is something like:
>>> 
>>> gen :: (a -> b) -> [MyType]
>>> gen f = [MyType (Just []) (Just c) (Just d) Nothing
>>>            | c <- f
>>>            | d <- [1,2,3,4]
>>> 
>>> When the gen function is used with take or any other function, only one value is returned.
>>> 
>>> Is there something here that can’t desugar properly to mzip that will still compile?
>>> 
>>> Note I did not test this specific code, I am just writing it here to represent the different pieces of a larger piece of real code which is below.
>>> 
>>> Mike
>>> 
>>> ———— Real Code ————
>>> 
>>> 
>>> data Config = Config {  onOffControl::Maybe [DEVICE_ON_OFF_CONTROL_BITS]
>>>                                   , seqUpPos::[Maybe ([DEVICE_SEQ_UP_POSITION_BITS], Word16)]
>>>                                   , seqDownPos::[Maybe ([DEVICE_SEQ_DOWN_POSITION_BITS], Word16)]
>>>                                   , tonTimers::[Maybe ([DEVICE_TON_TIMERS_BITS], Word16)]
>>>                                   , toffTimers::[Maybe ([DEVICE_TOFF_TIMERS_BITS], Word16)]
>>>                                   , vRange::Maybe [DEVICE_V_RANGE_BITS]
>>>                                   , vThresh::[Maybe (Word16, Word16)]
>>>                                   , rstbConfig::Maybe [DEVICE_RSTB_CONFIG_BITS]
>>>                                   , faultResponse::Maybe [DEVICE_FAULT_RESPONSE_BITS]
>>>                                   , breakpoint::Maybe ([DEVICE_BREAK_POINT_BITS], Word16)
>>>                                   , writeProtect::Maybe ([DEVICE_WRITE_PROTECTION_BITS], Word16)
>>>                                   , specialLot::Maybe Word16
>>>                                   , deviceId::Maybe Word16
>>>                                   , statusInfo::Maybe ([DEVICE_STATUS_INFORMATION_BITS])
>>>                                   , monitorStatus::Maybe ([DEVICE_MONITOR_STATUS_BITS])
>>>                                   , monitorStatusHistory::Maybe ([DEVICE_MONITOR_STATUS_HISTORY_BITS])
>>>                                   , monitorBackup::Maybe ([DEVICE_MONITOR_BACKUP_BITS])
>>>                                   , seqPosCount::Maybe ([DEVICE_SEQ_POSITION_COUNT_BITS], Word16)
>>> 
>>> generateConfigs seqValues delayValues threshValues = return [Config
>>>                                                                   (Just []) -- On off
>>>                                                                   ([Just (suPol, suPos),Just (suPol, suPos),Just (suPol, suPos),Just (suPol, suPos),Just (suPol, suPos),Just (suPol, suPos)])
>>>                                                                   ([Just (sdPol, sdPos),Just (sdPol, sdPos),Just (sdPol, sdPos),Just (sdPol, sdPos),Just (sdPol, sdPos),Just (sdPol, sdPos)])
>>>                                                                   ([Just ([tonMax], tonDelay),Just ([tonMax], tonDelay),Just ([tonMax], tonDelay),Just ([tonMax], tonDelay),Just ([tonMax], tonDelay),Just ([tonMax], tonDelay)])
>>>                                                                   ([Just ([toffMax], toffDelay),Just ([toffMax], toffDelay),Just ([toffMax], toffDelay),Just ([toffMax], toffDelay),Just ([toffMax], toffDelay),Just ([toffMax], toffDelay)])
>>>                                                                   (Just [rng1, rng2, rng3, rng4, rng5, rng6])
>>>                                                                   ([Just (threshOv, threshUv),Just (threshOv, threshUv),Just (threshOv, threshUv),Just (threshOv, threshUv),Just (threshOv, threshUv),Just (threshOv, threshUv)])
>>>                                                                   (Just ([rst_en] ++ [rst_time]))
>>>                                                                   (Just ([fault_number] ++ [fault_action] ++  [fault_delay] ++ fault_other ++ [fault_count]))
>>>                                                                   (Just ([], 0))
>>>                                                                   (Just ([], 0))
>>>                                                                   (Just 0)
>>>                                                                   Nothing
>>>                                                                   Nothing
>>>                                                                   Nothing
>>>                                                                   Nothing
>>>                                                                   Nothing
>>>                                                                   Nothing
>>>                                                                           | suPol <- [DEVICE_seq_up_position_bits]
>>>                                                                           | suPos <- seqValues
>>>                                                                           | sdPol <- [DEVICE_seq_down_position_bits]
>>>                                                                           | sdPos <- seqValues
>>>                                                                           | tonMax <- DEVICE_ton_timers_bits
>>>                                                                           | tonDelay <- delayValues
>>>                                                                           | toffMax <- DEVICE_toff_timers_bits
>>>                                                                           | toffDelay <- delayValues
>>>                                                                           | rng1 <- DEVICE_v_range_bits1
>>>                                                                           | rng2 <- DEVICE_v_range_bits2
>>>                                                                           | rng3 <- DEVICE_v_range_bits3
>>>                                                                           | rng4 <- DEVICE_v_range_bits4
>>>                                                                           | rng5 <- DEVICE_v_range_bits5
>>>                                                                           | rng6 <- DEVICE_v_range_bits6
>>>                                                                           | threshOv <- threshValues
>>>                                                                           | threshUv <- threshValues
>>>                                                                           | rst_time <- DEVICE_rstb_config_bits_time
>>>                                                                           | rst_en <- DEVICE_rstb_config_bits_en
>>>                                                                           | fault_number <- DEVICE_fault_response_bits_retry_number
>>>                                                                           | fault_other <- [DEVICE_fault_response_bits_other]
>>>                                                                           | fault_count <- DEVICE_fault_response_bits_count
>>>                                                                           | fault_delay <- DEVICE_fault_response_bits_delay
>>>                                                                           | fault_action <- DEVICE_fault_response_bits_action
>>>                                                             ]
>>> 
>>> generateSeqValues :: IO [Word16]
>>> generateSeqValues = do
>>> vs <- replicateM 10  (randomRIO (0x0000, 0x03FF))
>>> return vs
>>> 
>>> generateDelayValues :: IO [Word16]
>>> generateDelayValues = do
>>> vs <- replicateM 10 (randomRIO (0x0000, 0x1FFF))
>>> return vs
>>> 
>>> 
>>> generateThreshValues :: IO [Word16]
>>> generateThreshValues = do
>>> vs <- replicateM 10 (randomRIO (0x0000, 0x00FF))
>>> return vs
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe at haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe




More information about the Haskell-Cafe mailing list