2016-08-04 2 views
1

이 코드를 실행하려고 할 때마다, 컴파일러는 변수 redirectUrlGraphEmail, redirectUrlGraphPost, aboutContents에 대한 '없는 범위'오류를 반환하고, staticDir :튜플에 포함 된 변수를 정의하는 방법은 무엇입니까?

staticDir <- getStaticDir 
redirectUrlGraphEmail <- retrieveAuthURL testUrl 
redirectUrlGraphPost <- retrieveAuthURL testPostUrl 
aboutContents <- LazyIO.readFile $ markdownPath ++ "README.md" 
privacyContents <- LazyIO.readFile $ markdownPath ++ "PRIVACY.md" 
:

routes :: [ (String, ServerPart Response)] 
routes = [ 
("graph-fb", seeOther redirectUrlGraphEmail $ toResponse ""), 
("post-fb", seeOther redirectUrlGraphPost $ toResponse ""),    
("about", aboutResponse aboutContents), 
("static", serveDirectory DisableBrowsing [] staticDir)] 

이러한 변수에 의해 선언

하지만이 줄을 모듈에 어디에 추가해야하는지 잘 모르겠습니다. 도움이 필요 하신가요?

+0

전체 예제를 하나의 파일로 보여줄 수 있습니까? 변수가 전역 변수가되거나 일부 변수가 될 것으로 예상하는 것처럼 보입니다. –

답변

4

happstack을 모르지만 변수 redirectUrlGraphEmail 등이 주 (또는 일부 모나드)에서 정의 된 것 같습니다. 맞습니까? 그런 다음 모듈에서 별도의 함수로 route을 정의하려고합니다.

것은이

, 당신의 main에서 사용자가 정의하는 변수 (당신이 <-과 결합하는 것이 정확합니다) 당신의 main 로컬, 그래서 프로그램의 나머지 부분은 왜 컴파일러 인 (그들에 액세스 할 수 없습니다 그들이 routes에서 사용할 때 범위에 있지 않다는 것을 알려줍니다. 당신이 그들을 사용하려는 경우, 당신은 그래서 당신의 경우, 매개 변수로 복용 함수로 routes를 정의 할 필요가 : 당신이 바인딩을했습니다 변수와 main 전화 routes에서 다음

routes redirectUrlGraphEmail redirectUrlGraphPost = [ 
("graph-fb", seeOther redirectUrlGraphEmail $ toResponse ""), 
("post-fb", seeOther redirectUrlGraphPost $ toResponse ""),    
("about", aboutResponse aboutContents), 
("static", serveDirectory DisableBrowsing [] staticDir)] 

그리고있다. 나는 이해가 되니?

+0

네, 저에게 많은 의미가 있습니다. 당신의 설명에 감사드립니다! 여기에있는 또 다른 질문은 주요 모듈에 있습니다.'routes'는'dir' 함수를'routes (경로)의 각 튜플에 매핑하는'(map (\ (a, b) -> dir ab) $ routes) '. 'dir'은 튜플의 두 요소를 변수로 취합니다. 내가 바인딩 한 변수와 함께 main에서'routes'를 호출하는 것과 어떻게 조합 할 수 있습니까? –

+0

당신의 질문을 올바르게 이해했다면, 단순히'routes'를 인자에 적용 할 수 있습니다. 그래서'map (\ (a, b) -> dir a b) $ routes redirectUrlGraphEmail redirectUrlGraphPost ...'라고 쓸 수 있습니다. 원래 공식에서'$'를 쓸 필요가 없다는 것에주의하십시오.'map (\ (a, b) -> dir a b) routes'는 괜찮을 것입니다;) – villou24

+0

봐요! 그런 다음 내 노선 기능에 해당 변수를 추가해야합니까? 경로 '등 :: [(문자열 ServerPart 대응)] 노선 staticDir redirectUrlGraphEmail redirectUrlGraphPost aboutContents privacyContents = ("그래프 FB"seeOther redirectUrlGraphEmail $ toResponse "") ("포스트 FB"seeOther redirectUrlGraphPost $ toResponse "("about ", aboutResponse aboutContents), ("static ", serveDirectory DisableBrowsing [] staticDir)] ' –

관련 문제