scotty-web / scotty

Haskell web framework inspired by Ruby's Sinatra, using WAI and Warp (Official Repository)
http://hackage.haskell.org/package/scotty
BSD 3-Clause "New" or "Revised" License
1.72k stars 134 forks source link

Variable not in scope: pathParam In examples/basic.hs file #355

Closed fongfiafia closed 10 months ago

fongfiafia commented 10 months ago

Hello!

I am new to Haskell and Scotty. I am processing examples in basic.hs and I encountered an error (look at the pic below).

image

this is my cabal file, I think I am using the latest version.

Name:                scotty-examples
Version:             0.1
Synopsis:            scotty examples
Homepage:            https://github.com/scotty-web/scotty
Bug-reports:         https://github.com/scotty-web/scotty/issues
License:             BSD3
License-file:        LICENSE
Author:              Andrew Farmer <xichekolas@gmail.com>
Maintainer:          Andrew Farmer <xichekolas@gmail.com>
Copyright:           (c) 2012-Present, Andrew Farmer and the Scotty contributors
Category:            Web
Stability:           experimental
Build-type:          Simple
Cabal-version:       >= 1.10
Description:         Example programs using @scotty@
tested-with:         GHC == 8.10.7
                   , GHC == 9.0.2
                   , GHC == 9.2.8
                   , GHC == 9.4.6
                   , GHC == 9.6.2

executable CarShop
  main-is:             main.hs
  default-language:    Haskell2010
  hs-source-dirs:      src
  build-depends:       base >= 4.6 && < 5,
                       http-types,
                       mtl,
                       random,
                       scotty == 0.20.1,
                       text,
                       wai-extra
  GHC-options:         -Wall -threaded

I find it will work when using queryParam. I don't know why, but maybe it is better to fix the problem in the examples.

Finally, if you consider it as a problem, maybe I can try to make an easy-fix pull request for you.

ocramz commented 10 months ago

Hi @fongfiafia , could you share the imports block in your main.hs ?

fongfiafia commented 10 months ago

Hi @fongfiafia , could you share the imports block in your main.hs ?

sure~

{-# LANGUAGE OverloadedStrings #-}

module Main (main) where

import Web.Scotty

main :: IO ()
main = do
    scotty 8081 $
        get "/user" $ do
            v <- pathParam "uid"
            html $ mconcat ["<h1>", v, "</h1>"]
ocramz commented 10 months ago

@fongfiafia ah I got it now. pathParam is not released yet (it's only in the master branch for now). Please refer to the release documentation on Hackage : https://hackage.haskell.org/package/scotty .