• Newbie needing help

    From Steve Graham@21:1/5 to All on Fri Dec 13 17:14:21 2019
    Long-time programmer/newbie with Haskell...

    Thought I'd check out a program I saw at https://programmingpraxis.com/2019/12/13/pentabonacci-numbers/#comments:

    pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t
    take 20 (pdiv [1] [-1,-1])
    take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])

    I entered at the Haskell Online Compiler (https://paiza.io/projects/HEXouZ1jmJjemSO1cULHoA?language=haskell) and on my iOS Haskell app and got the same error:

    [1 of 1] Compiling Main ( Main.hs, Main.o )

    Main.hs:3:1: error:
    Parse error: naked expression at top level
    Perhaps you intended to use TemplateHaskell

    Interestingly on my Windows 10 GHCi app, it worked fine:

    GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help
    Prelude> pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t Prelude> take 20 (pdiv [1] [-1,-1]) [1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765]
    Prelude> take 20 (pdiv [0,1] [-1,-1,-1,-1,-1]) [0,1,1,2,4,8,16,31,61,120,236,464,912,1793,3525,6930,13624,26784,52656,103519] Prelude>

    I'm sure it's some formatting issue. I would appreciate any assistance you folks could offer.

    Thanks, Steve

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Steve Graham@21:1/5 to Ben Bacarisse on Fri Dec 13 18:12:12 2019
    On Friday, December 13, 2019 at 6:07:18 PM UTC-8, Ben Bacarisse wrote:
    Steve Graham <xxxx> writes:

    Long-time programmer/newbie with Haskell...

    Thought I'd check out a program I saw at https://programmingpraxis.com/2019/12/13/pentabonacci-numbers/#comments:

    pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t
    take 20 (pdiv [1] [-1,-1])
    take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])

    I entered at the Haskell Online Compiler (https://paiza.io/projects/HEXouZ1jmJjemSO1cULHoA?language=haskell)
    and on my iOS Haskell app and got the same error:

    [1 of 1] Compiling Main ( Main.hs, Main.o )

    Main.hs:3:1: error:
    Parse error: naked expression at top level
    Perhaps you intended to use TemplateHaskell

    Interestingly on my Windows 10 GHCi app, it worked fine:

    GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help
    Prelude> pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t
    Prelude> take 20 (pdiv [1] [-1,-1]) [1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765] Prelude> take 20 (pdiv [0,1] [-1,-1,-1,-1,-1]) [0,1,1,2,4,8,16,31,61,120,236,464,912,1793,3525,6930,13624,26784,52656,103519]
    Prelude>

    I'm sure it's some formatting issue. I would appreciate any
    assistance you folks could offer.

    It's not a formatting issue. The interpreter will take expressions and evaluate them, but a Haskell program, suitable for compilation, can't
    have "top-level" expressions.

    The compilable, "program" version of what you wrote is

    pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t

    main = do
    print $ take 20 (pdiv [1] [-1,-1])
    print $ take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])

    You would see the same error if you used ghc (rather than ghci) on your Windows box:

    $ ghc p.hs
    [1 of 1] Compiling Main ( p.hs, p.o )

    p.hs:2:1: error:
    Parse error: module header, import declaration
    or top-level declaration expected.
    |
    2 | take 20 (pdiv [1] [-1,-1])
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^

    --
    Ben.

    Thanks, Ben. The default for a new iOS Haskell program is:

    main = do
    putStr ""

    Guess I should have realized that main = do was meant to be part of programs, at least some of them.

    Steve

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Steve Graham on Sat Dec 14 02:07:16 2019
    Steve Graham <solitary.wanderer52@gmail.com> writes:

    Long-time programmer/newbie with Haskell...

    Thought I'd check out a program I saw at https://programmingpraxis.com/2019/12/13/pentabonacci-numbers/#comments:

    pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t
    take 20 (pdiv [1] [-1,-1])
    take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])

    I entered at the Haskell Online Compiler (https://paiza.io/projects/HEXouZ1jmJjemSO1cULHoA?language=haskell)
    and on my iOS Haskell app and got the same error:

    [1 of 1] Compiling Main ( Main.hs, Main.o )

    Main.hs:3:1: error:
    Parse error: naked expression at top level
    Perhaps you intended to use TemplateHaskell

    Interestingly on my Windows 10 GHCi app, it worked fine:

    GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help
    Prelude> pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t Prelude> take 20 (pdiv [1] [-1,-1]) [1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765]
    Prelude> take 20 (pdiv [0,1] [-1,-1,-1,-1,-1]) [0,1,1,2,4,8,16,31,61,120,236,464,912,1793,3525,6930,13624,26784,52656,103519]
    Prelude>

    I'm sure it's some formatting issue. I would appreciate any
    assistance you folks could offer.

    It's not a formatting issue. The interpreter will take expressions and evaluate them, but a Haskell program, suitable for compilation, can't
    have "top-level" expressions.

    The compilable, "program" version of what you wrote is

    pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t

    main = do
    print $ take 20 (pdiv [1] [-1,-1])
    print $ take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])

    You would see the same error if you used ghc (rather than ghci) on your
    Windows box:

    $ ghc p.hs
    [1 of 1] Compiling Main ( p.hs, p.o )

    p.hs:2:1: error:
    Parse error: module header, import declaration
    or top-level declaration expected.
    |
    2 | take 20 (pdiv [1] [-1,-1])
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)