우리는 목록 내포에 대한 조건을 결정하는 함수를 넣을 수 있습니까? 여기에 내가 구현하려고 내 코드입니다 :하스켈 (Haskell)의 목록 내포 함수에서 함수를 사용 하시겠습니까?
mQsort :: [String] -> [F.Record] -> [F.Record]
mQsort [] _ = []
mQsort [email protected](col:cond:cs) [email protected](x:xs) = (mQsort c small) ++ mid ++ (mQsort c large)
where
small = [y | y<-xs, (qGetStr col y) (qGetCond cond) (qGetStr col x)]
mid = mQsort cs [y | y<-l, (qGetStr col y) == (qGetStr col x)]
large = [y | y<-xs, (qGetStr col y) (qGetCond' cond) (qGetStr col x)]
qGetStr :: String -> F.Record -> String
qGetStr col r | U.isClub col = F.club r
| U.isMap col = F.mapName r
| U.isTown col = F.nearestTown r
| U.isTerrain col = F.terrain r
| U.isGrade col =F.mapGrade r
| U.isSW col = F.gridRefOfSWCorner r
| U.isNE col = F.gridRefOfNECorner r
| U.isCompleted col = F.expectedCompletionDate r
| U.isSize col = F.sizeSqKm r
| otherwise = ""
qGetCond "ascending" = (<)
qGetCond "decending" = (>)
qGetCond' "ascending" = (>)
qGetCond' "decending" = (<)
내가 함수 qGetStr 대신 또한 2
의 4 개 인자에 적용됩니다 없다는 오류를 얻을 qGetCond -이은을 반환 할 수있는 권리 구문입니다 운영자. 나는 때문에 컴파일 오류에 괄호 연산자를 배치했다,하지만 난 large
에 대한 유사
small = [y | y<-xs, (qGetCond cond) (qGetStr col y) (qGetStr col x)]
와
small = [y | y<-xs, (qGetStr col y) (qGetCond cond) (qGetStr col x)]
교환이
당신은 ['sortBy']에 관심이있을 수 있습니다 (http://hackage.haskell.org/packages/archive/base/latest/doc/ : 구문과 미묘한 몇 가지 있습니다 html/Data-List.html # v : sortBy). –