eagletmt / ghcmod-vim

Happy Haskell programming on Vim, powered by ghc-mod
http://www.vim.org/scripts/script.php?script_id=4473
433 stars 59 forks source link

ghcmod.vim should support the split, sig, and refine commands #68

Open cdepillabout opened 9 years ago

cdepillabout commented 9 years ago

ghcmod added support for split, sig, and refine commands. This is similar to the functionality available in Idris and Agda plugins.

split: https://github.com/kazu-yamamoto/ghc-mod/pull/274

    - split FILE [MODULE] LINE COL
        Split a function case by examining a type's constructors.

        For example given the following code snippet:

            f :: [a] -> a
            f x = _body

        would be replaced by:

            f :: [a] -> a
            f [] = _body
            f (x:xs) = _body

sig: https://github.com/kazu-yamamoto/ghc-mod/pull/274

    - sig FILE MODULE LINE COL
        Generate initial code given a signature.

        For example when (LINE,COL) is on the signature in the following
        code snippet:

            func :: [a] -> Maybe b -> (a -> b) -> (a,b)

        ghc-mod would add the following on the next line:

            func x y z f = _func_body

refine: https://github.com/kazu-yamamoto/ghc-mod/issues/311

    - refine FILE MODULE LINE COL EXPR
        Refine the typed hole at (LINE,COL) given EXPR.

        For example if EXPR is `filter', which has type `(a -> Bool) -> [a]
          -> [a]' and (LINE,COL) is on the hole `_body' in the following
        code snippet:

            filterNothing :: [Maybe a] -> [a]
            filterNothing xs = _body

        ghc-mod changes the code to get a value of type `[a]', which   
        results in:

            filterNothing xs = filter _body_1 _body_2
ches commented 9 years ago

FYI there is work for split on #69.

eagletmt commented 9 years ago

Added support for ghc-mod sig . I also tried to support ghc-mod refine, but I couldn't find how to use it.

module Refine where

filterNothing :: [Maybe a] -> [a]
filterNothing xs = _body

ghc-mod refine Refine.hs Refine 4 20 filter outputs nothing. Could you show me a working example?

I'm using https://github.com/kazu-yamamoto/ghc-mod/tree/4b2be9c9edbd377c3d95b6685ab53e7c5270edea compiled with GHC 7.10.1.

albertnetymk commented 9 years ago

I think your usage is correct. Using this hello-world like repo, and ghc-mod refine src/main.hs Main 4 20 filter, I get this:

4 20 4 25 "filter _body_1 _body_2"
DanielG commented 9 years ago

All that stuff is broken with 7.10 ATM. See https://github.com/kazu-yamamoto/ghc-mod/issues/438