如何使此功能不添加任何内容?

时间:2019-01-04 02:38:37

标签: haskell

有什么办法可以在列表理解中不添加任何内容?

我写了以下函数

toShape :: AltShape -> Shape
toShape ps = splitEvery (rowLength ps) 
            [ if (row `notElem` (map coords ps)) 
              then (lookup row (table ps)):r 
              else Nothing
               | row <- allCoords (colLength ps) (rowLength ps) ]

其中AltShape和Shape定义为:

type AltShape = [Point]
data Point = P Colour (Int,Int)  deriving (Eq,Show)

type Shape = [Row]
type Row = [Square]
type Square = Maybe Colour

data Colour = Black | Red | Green   deriving (Eq,Show)

基本上,该功能应该将AltShapes转换为Shapes。我一直在尝试通过创建一个函数来实现此目的,该函数根据形状的宽度和高度创建所有可能的坐标,然后将它们与形状中的实际点进行匹配。如果有匹配项,我想将Just c添加到列表中,其中c是颜色,如果没有匹配项,我希望它将Nothing添加到列表中。但是现在我只得到Just c的列表。我应该怎么写呢?

1 个答案:

答案 0 :(得分:1)

使用警卫

<div class="col-lg-10">
    <div class="float-right">
        <form role="form" class="form-inline" method="get">
            <div class="form-group" id="data_5">
                <div class="input-group my-2" id="datepicker">
                    <input type="date" class="input-sm form-control" name="start_date" value="2019-01-03" max="2019-01-04">
                    <span class="input-group-addon input-group-sm">to</span>
                    <input type="date" class="input-sm form-control" name="end_date" value="2019-01-03" max="2019-01-04">
                    <div class="input-group-append">
                        <button class="btn mt-2 btn-sm btn-success" type="submit">Update</button>
                        <button type="button" class="reset btn mt-2 btn-sm btn-primary" data-column="0" data-filter="">
                            <i class="bootstrap-icon-white glyphicon glyphicon-filter"></i> Reset filters
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>