haskell - Any way to add patterns, type signature, to a function in GHCi? -


^ - No, it does not completely. Including my question involves interacting pattern and type signature ... which is apparently impossible.

X: foo xs

if you do this on foo.hs and the GHCi prompt type : load foo.hs . You can then invite Foo to the list and get the list back.

The beginner Google search tells you that you need the let statement in GHCI but in this case (the function defined with many patterns) this will not work:

  prelude & gt; Let foo [] = [] Introduction & gt; Let foo (x: xs) = x: foo xs preface & gt; Foo [1, 2, 3] [1,2,3 *** Exception: & lt; Interactive>: 3: 5-27: non-full pattern foo  in the function 

The second "let's" overwrite the first "let". Let's go out is not an option. And if you foo :: [a] - & gt; Do not like it if you type in the expression [A] either.

Tutorials tend to tilt it and send you your code quickly in the file. If you do not want to create a file, and want to do interactive work, what will happen? What are the options?

not

for that matter, you should "add" it as You should not look at a line, after which you can not add new patterns or a type of signature to the function in GHCI. By-line basis in source code, either it is only a notation feature, so when you look like "multi-line" definition:

  foo :: [a] - & gt; [A] foo [] = [] foo (x: xs) = x: foo xs  

Those FU definitions should be tied together as a group. You can not divide them ... So for example, this would be the cause of an error:

  foo :: [a] - & gt; [A] foo [] = [] times = 3 fu (x: xs) = x: foo xs  

(Note: Type signatures may be different, though. / Em>

To talk things together as a group, you can use multi-line input in GHCI. Or you can do it all in one line with a semicolon: < Foo: [A] - Foo [] = []; Foo (x: xs) = x: xs

P> But you can not type in any input, test it, then in different pattern patch and so on Can make out, and check it again. The function of each let .


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -