From 09f89fc71e6a646e226b2f0bc7e5ba44ce87864e Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 13 Mar 2019 00:19:40 -0400 Subject: use type alias 'String' --- GenSCAD.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/GenSCAD.hs b/GenSCAD.hs index 5989c65..e9343da 100644 --- a/GenSCAD.hs +++ b/GenSCAD.hs @@ -22,7 +22,7 @@ import System.Process _V32l :: R3 c1 => c1 c -> [c] _V32l c = [c ^. _x, c ^. _y, c ^. _z] -_V32s :: (R3 c1, Show a) => c1 a -> [Char] +_V32s :: (R3 c1, Show a) => c1 a -> String _V32s c = intercalate "," (map show (_V32l c)) -- placecube: OpenSCAD translate cube described by d to place designated by p @@ -30,19 +30,19 @@ _V32s c = intercalate "," (map show (_V32l c)) -- translate([1, 2, 3]) { cube([10, 20, 30]); } --crandrgb = intercalate "," -color :: [Char] -> [Char] -> [Char] +color :: String -> String -> String color rgb what = "color ([" ++ rgb ++ "]) {" ++ what ++ "}" -translate :: [Char] -> [Char] -> [Char] +translate :: String -> String -> String translate to what = "translate([ " ++ to ++ "]) { " ++ what ++ " }" -cube :: [Char] -> [Char] +cube :: String -> String cube d = "cube([ " ++ d ++ "]);" -cubeat :: [Char] -> [Char] -> [Char] +cubeat :: String -> String -> String cubeat d here = translate here $ (cube d) -colorcubeat :: [Char] -> [Char] -> [Char] -> [Char] +colorcubeat :: String -> String -> String -> String colorcubeat rgb d pos = color rgb $ translate pos $ cube d --place [x] = "ERROR" -place :: [[Char]] -> [Char] +place :: [String] -> String place [d, p] = cubeat d p place [r, d, p] = colorcubeat r d p @@ -54,7 +54,7 @@ place [r, d, p] = colorcubeat r d p --scad [] = [] --scad obj = (place (head obj)) ++ "\n" ++ scad (tail obj) -scad :: [([Char], [Char])] -> [Char] +scad :: [(String, String)] -> String scad [(d, p)] = cubeat p d --scad [(r, d, p)] = colorcubeat r d p --scad [x] = if (length x == 3) then (colorcubeat (x !! 0) (x !! 1) (x !! 2)) @@ -62,7 +62,7 @@ scad [(d, p)] = cubeat p d --scad (x:s) = scad [x] ++ scad s -placecube :: (R3 c2, R3 c3, Show a1, Show a2) => (c2 a1, c3 a2) -> [Char] +placecube :: (R3 c2, R3 c3, Show a1, Show a2) => (c2 a1, c3 a2) -> String placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(snd obj) ++ " ]); }" --placecube (p,d) = printf "translate([%d, %d, %d]) { cube([%d, %d, %d]); }" (_V32l p ++ _V32l d) @@ -75,12 +75,12 @@ placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(sn --td = [(V3 0 1 2, V3 10 20 30), (V3 50 51 52, V3 11 22 33)] ---genscad :: [(V3 p, V3 d)] -> [Char] +--genscad :: [(V3 p, V3 d)] -> String --genscad objs = concat $ map (++ "\n") $ map placecube objs --scad (c, p, d) = colorcubeat c d p --scad (p,d) = cubeat d p -genscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> [Char] +genscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> String genscad objs = concat $ map (++ "\n") $ map (placecube) objs printscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> IO () printscad objs = putStrLn $ genscad objs -- cgit v1.2.3